The Geometry Modules¶
core.opsim_geo¶
Definitions / declarations for geometrical objects and functions used in DOSSS.
-
class
core.opsim_geo.DOSSSLine(a=None, u=None)¶ Represents a line of the form P = a + lambda * u where u gives the direction of the line and a is the base of the line. Distances along the line are measured relative to this point.
Parameters: - a (DOSSSVector) – Base point of the line. If None, it defaults to (0,0).
- u (DOSSSVector) – Direction of the line. If None, it defaults to (1,0).
-
bounded_intersection(l, p1, p2)¶ Return the intersection of a line l (DOSSSLine) with the current line (DOSSSVector) only if it lies between the points p1 (DOSSSVector) and p2 (DOSSSVector), otherwise returns None.
-
contains_point(p)¶ Returns True if point p is part of the line, False otherwise.
-
get_normal(p)¶ Returns a line orthogonal to this line through the specified point p (DOSSSVector).
-
get_point(l)¶ Return point for lambda value l.
-
intersect(l)¶ Returns the intersection of a line with the current line (DOSSSVector) or None if the lines are parallel or identical.
-
isLambdaPositiveForPoint(p)¶ Return True if point p (DOSSSVector) is in the positive half space of the line, i.e. lambda is positive. Returns False otherwise.
-
mirror(l)¶ Mirror the current line on another line l. The new base point is the intersection of the two lines.
-
rotate(alpha)¶ Returns a copy of the current line rotated by an angle alpha (in degrees).
-
class
core.opsim_geo.DOSSSVector(nx=0, ny=0)¶ A 2d vector class that supports basic arithmetic operations (+, -, *).
Parameters: - nx (float) – x-component (optional).
- ny (float) – y-component (optional).
-
isNull()¶ Returns True if vector is identical to zero, False otherwise.
-
length()¶ Return length of vector.
-
rotate(theta)¶ Rotate vector.
Parameters: theta (float) – Angle in degrees. Returns: Rotated vector.
-
setx(x)¶ Overwrite x-component of vector.
Parameters: x (float) – New value for x-component.
-
sety(y)¶ Overwrite y-component of vector.
Parameters: y (float) – New value for y-component.
-
unit()¶ Returns a unit vector with the same orientation.
-
x()¶ Returns x-component of vector. If absolute value is below 1e-10, it returns 0.
-
y()¶ Returns y-component of vector. If absolute value is below 1e-10, it returns 0.
-
core.opsim_geo.IntersectionWithParabola(line, f)¶ Calculate the intersection between a line and a parabola.
Parameters: - line (DOSSSLine) – The line.
- f (float) – Focal length of the parabola.
Returns: Intersection(s) (Sequence of DOSSSVectors of length [0, 1, 2])
-
core.opsim_geo.IntersectionWithSphere(line, x0, R)¶ Calculate the intersection between a line and a sphere.
Parameters: - line (DOSSSLine) – The line.
- x0 (DOSSSVector) – Center of the sphere.
- R (float) – Radius of the sphere.
Returns: Intersection(s) (Sequence of DOSSSVectors of length [0, 1, 2]).
-
core.opsim_geo.Snell(u, n, ior=0)¶ Apply Snell’s law to a vector.
Parameters: - u (DOSSSVector) – Incident vector.
- n (DOSSSVector) – Surface normal vector.
- ior (float) – Index of refraction of the refracting object (ior != 0). Set to zero to calculate reflected vector.
Returns: Refracted (ior != 0) or reflected (ior == 0) vector.
-
core.opsim_geo.getLineThroughPoints(p1, p2)¶ Create a DOSSSLine object defined by two points p1 (DOSSSVector) and p2 (DOSSSVector).
core.opsim_lightray¶
Definitions / declarations for light rays for use in DOSSS.
-
class
core.opsim_lightray.DOSSS_LightRay(posx=0, posy=0, ux=1, uy=0)¶ A light ray class used for raytracing in DOSSS. All coordinates are given in laboratory system.
Parameters: - posx (float) – x-coordinate of the base point.
- posy (float) – y-coordinate of the base point.
- ux (float) – x-component of the direction vector.
- uy (float) – y-component of the direction vector.
-
ContinueRay(dc, px, py, ux, uy)¶ Calculate the continuation of the light ray beyond the last intersecting object for proper display on screen.
All coordinates are given in DC client system, i.e. range from 0 to size of screen in px.
Parameters: - dc (wx.DC) – Paint DC.
- px (float) – x-coordinate of the base point.
- py (float) – y-coordinate of the base point.
- ux (float) – x-component of the direction vector.
- uy (float) – y-component of the direction vector.
Returns: Lambda value of intersection with screen boundary (float).
-
Draw(dc, zoom, ox, oy)¶ Draw the light ray to the DC client.
Parameters: - dc (wx.DC) – Paint DC.
- zoom (float) – Zoom level, where 1 is no zoom.
- ox (float) – x-coordinate of origin of current view in laboratory frame.
- oy (float) – y-coordinate of origin of current view in laboratory frame.
-
getCurLine()¶ Returns DOSSSLine object for current part of the beam.
-
svgstr()¶ Returns a string in SVG format for exporting to vector format.
-
core.opsim_lightray.fromLine(l)¶ Convert a DOSSSLine object into a DOSSS_LightRay object.