geoptics.elements package¶
Package contents¶
Package containing elements.
The physical scene is two-dimensional.
First, it has an infinite background region (air by default),
and possibly contains several regions of different materials.
Regions are defined in the regions submodule.
Second, sources emit rays of light.
Rays must have a source,
from the sources submodule.
Rays propagation takes place
in the rays submodule.
The elements can be used alone, and form a consistent framework.
But if a graphical representation is desired, the current preferred procedure
is to start from the qt package.
Elements glossary¶
- element¶
- elements¶
Object living in a scene. It can be a physical element like a source or a region, or geometrical objects such as segments or arcs.
- index¶
- optical index¶
- refractive index¶
Number characteristic of the propagation of light in a material. Currently only transparent materials are handled, so the index is real. For instance, silica glass has an index close to 1.5 in the visible range.
- line¶
- lines¶
Shorthand for half-line, defined by a starting Point and a Vector direction.
- scene¶
Physical area where elements live.
- z_value¶
- z_values¶
The z_value determines the “altitude” of an element. Elements with a higher z_value are drawn on top. Elements with lower z_value can be hidden by elements with a higher z_value.
Submodules imports¶
The python standard syntax to import submodules is
>>> from geoptics.elements.scene import Scene
>>> from geoptics.elements.sources import Beam
>>> scene = Scene()
>>> beam = Beam(scene=scene)
To make guis modules more readable, another route is provided by GeOptics:
>>> from geoptics import elements
>>> scene = elements.scene.Scene()
>>> beam = elements.sources.Beam(scene=scene)
This is mostly useful in guis modules to easily distinguish
the elements Beam from the local gui Beam
(since the element name starts with elements.).
In user scripts, this is not useful, and the previous way is preferred.
Submodules¶
geoptics.elements.arc module¶
Define an arc of a circle.
- class geoptics.elements.arc.Arc(M1, M2, tangent)[source]¶
Bases:
objectArc of a circle.
- Parameters:
- __contains__(M)[source]¶
Return True if the point M belongs to the arc sector.
Distances are not checked.
- property config¶
Configuration dictionary.
- intersection(other, sign_of_s=0)[source]¶
Intersections of the arc with another element.
- Parameters:
- Returns:
list of intersections
- Return type:
listofIntersection
- translate(**kwargs)[source]¶
Translate the segment as a whole.
Same syntax and same side effects as
geoptics.elements.vector.Point.translate()Likewise, it is possible to insert a .copy() to avoid side-effects. FIXME: copy() not implemented yet…
- Returns:
self, for convenience
Examples
>>> from geoptics.elements.vector import Point, Vector >>> M1 = Point(110, 190) >>> M2 = Point(120, 60) >>> tg = Vector(10, -20) >>> arc = Arc(M1, M2, tg) >>> arc.C Point(-44.54545454545456, 112.72727272727272) >>> tr = Vector(5, 15) >>> arc.translate(dv=tr) >>> arc.M1 Point(115, 205) >>> arc.M2 Point(125, 75) >>> arc.C Point(-39.54545454545456, 127.72727272727272)
geoptics.elements.line module¶
Define Lines.
- class geoptics.elements.line.Intersection(p: Point, s: float, eN: Vector, eT: Vector)[source]¶
Bases:
NamedTupleIntersection between a
Lineand another element- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('p', 's', 'eN', 'eT')¶
- classmethod _make(iterable)¶
Make a new Intersection object from a sequence or iterable
- _replace(**kwds)¶
Return a new Intersection object replacing specified fields with new values
- class geoptics.elements.line.Line(p=None, u=None)[source]¶
Bases:
objectLine defined by a point p and a direction vector u.
- property config¶
Configuration dictionary.
- classmethod from_config(config)[source]¶
Alternate constructor.
Examples
>>> from geoptics.elements.vector import Point, Vector >>> p = Point(10, 20) >>> u = Vector(30, 60) >>> line1 = Line(p, u) >>> config = line1.config >>> line2 = Line.from_config(config) >>> line2.config == config True
- static interpolate(line_start, line_end, x)[source]¶
Interpolated line.
The returned line is interpolated between two given lines, going ccw from line_start to line_end.
The interpolation is done on Line.p and on the Line.u angle.
- intersection(other, sign_of_s=0)[source]¶
Intersections of the line with another line.
- Parameters:
- Returns:
list either empty (no intersection), or holding a single intersection.
This is done for consistency with other elements that can have multiple intersections with a line.
- Return type:
listofIntersection
- tangent(normalized=False)[source]¶
Return a tangent vector to the line.
For a line, this is basically u itself.
- translate(**kwargs)[source]¶
Translate the starting point.
Same syntax and same side effects as
geoptics.elements.vector.Point.translate()Likewise, it is possible to insert a
.copy()to avoid side-effects.return self for convenience
geoptics.elements.rays module¶
Rays of light.
Part should not be used directly.
Actually, even Ray should not be used directly.
Users wanting a single ray should instanciate a
SingleRay source.
- class geoptics.elements.rays.Part(line=None, s=None, n=None)[source]¶
Bases:
objectStraight part of a ray.
- property config¶
Configuration dictionary.
- classmethod from_config(config)[source]¶
Alternate constructor.
Examples
>>> from geoptics.elements.vector import Point, Vector >>> from geoptics.elements.line import Line >>> from geoptics.elements.rays import Ray >>> p = Point(10, 20) >>> u = Vector(30, 60) >>> line1 = Line(p, u) >>> s = 100 >>> n = 1.5 >>> part1 = Part(line1, s, n) >>> config = part1.config >>> part2 = Part.from_config(config) >>> part2.config == config True
- line¶
starting point and direction
- s¶
length
- translate(**kwargs)[source]¶
Translate the part as a whole.
Same syntax and same side effects as
geoptics.elements.vector.Point.translate()Likewise, it is possible to insert a
.copy()to avoid side-effects. FIXME:copy()not implemented yet…return self for convenience
- class geoptics.elements.rays.Ray(line0=None, s0=100, source=None, n=None, tag=None)[source]¶
Bases:
objectA ray of light.
A ray must have a source. normally rays are not created directly. Use one of the sources module objects instead.
- Parameters:
- add_part(u, s, n=None)[source]¶
Add a new part to the ray.
- Parameters:
u (Line) – starting point and direction for that part
s (float) – length of that part
n (float, optional) – optical index encountered by that part.
- property config¶
Configuration dictionary.
- draw()[source]¶
Draw the ray.
This method does nothing in the elements realm, but should be overloaded is there is a graphical counterpart In this case, the ray should be (re)drawn
- classmethod from_config(config, source=None, tag=None)[source]¶
Alternate constructor.
Examples
>>> from geoptics.elements.vector import Point, Vector >>> from geoptics.elements.line import Line >>> from geoptics.elements.rays import Ray >>> p = Point(10, 20) >>> u = Vector(30, 60) >>> line1 = Line(p, u) >>> s = 100 >>> n = 1.5 >>> ray1 = Ray(line0=line1, s0=s, n=n) >>> config = ray1.config >>> ray2 = Ray.from_config(config) >>> ray2.config == config True
- translate(**kwargs)[source]¶
Translate the ray as a whole.
Same syntax and same side effects as
geoptics.elements.vector.Point.translate()Likewise, it is possible to insert a
.copy()to avoid side-effects. FIXME:copy()not implemented yet…return self for convenience
geoptics.elements.regions module¶
Define regions.
Specific region classes should inherit from the generic Region.
Currently an all-purpose Polycurve is available.
- class geoptics.elements.regions.Polycurve(n=None, scene=None, tag=None)[source]¶
Bases:
RegionDefine a region inside curves (line segments, arcs, …).
- Parameters:
n (float) – optical index of the region
M1 (Point) – first point
tag (str) – tag for this region
- Returns:
a region
- Return type:
- add_arc(M_next, tangent)[source]¶
Add an
Arccurve to the boundary.The arc starts from the last point with the given tangent, and ends on M_next.
- add_line(M_next)[source]¶
Add a straight section to the region boundary.
The added section is actually a
Segment, between the last point and the given M_next point.
- property config¶
Configuration dictionary.
- intersection(other, sign_of_s=0)[source]¶
Return the intersections between the region boundaries and other.
Args: same as
elements.segment.Segment.intersection()
- translate(**kwargs)[source]¶
Translate the region as a whole.
Same syntax and same side effects as
geoptics.elements.vector.Point.translate()Likewise, it is possible to insert a
.copy()to avoid side-effects. FIXME:copy()not implemented yet…Return self for convenience
- class geoptics.elements.regions.Region(n=None, scene=None)[source]¶
Bases:
objectRegion of space.
- contains(point=None, u=None, line=None)[source]¶
Is a given point contained in this region ?
Alternatively, line can be given, in which case point is taken from line.p, and u from line.u.
- intersection(other, sign_of_s=0)[source]¶
Return the intersections between the region boundaries and other.
By default, return an empty list. This method should be overloaded by specific region classes.
Args: same as
elements.segment.Segment.intersection()
- scene¶
physical scene where the region will be placed
geoptics.elements.scene module¶
Define a Scene, and hold all the propagation calculations.
- class geoptics.elements.scene.Scene[source]¶
Bases:
objectScene holding all items.
- background¶
background medium (air by default)
- property config¶
Configuration dictionary.
- region_at(*args, **kwargs)[source]¶
Return the region where the given point belongs to.
In case of overlapping self.regions, return the first one found.
Args: same as meth:geoptics.elements.regions.Region.contains
- Returns:
- the region point belongs to.
(or self.background if inside no region)
- Return type:
- regions¶
list of all regions, excluding background
- sources¶
list of all sources
geoptics.elements.segment module¶
Define a geometric Segment [M1, M2].
- class geoptics.elements.segment.Segment(M1, M2)[source]¶
Bases:
objectSegment defined by its two ends: M1 et M2.
- property config¶
Configuration dictionary.
- intersection(other, sign_of_s=0)[source]¶
Intersections of the segment with another element.
- Parameters:
- Returns:
list of intersections
- Return type:
listofIntersection
- translate(**kwargs)[source]¶
Translate the segment as a whole.
Same syntax and same side effects as
geoptics.elements.vector.Point.translate()Likewise, it is possible to insert a
.copy()to avoid side-effects. FIXME:copy()not implemented yet…return self for convenience
geoptics.elements.sources module¶
Sources of light rays.
This is the correct way for a user to generate and control rays.
Currently available sources are:
SingleRayfor a single ray (surprise !)Beamfor a beam of light with evenly spaced rays. TheBeamis very generic. Rays can be diverging, parallel, or focused. The source can be extended or point-like.
- class geoptics.elements.sources.Beam(line_start=None, s_start=None, line_end=None, s_end=None, N_inter=0, scene=None, tag=None)[source]¶
Bases:
SourceBeam of rays.
The Beam is defined by two extreme rays (first and last). Intermediate rays positions and angles (lines) are evenly interpolated between the first and last ray.
- Parameters:
- Returns:
Source with N_inter + 2 (first and last) rays.
- class geoptics.elements.sources.SingleRay(line0=None, s0=None, scene=None, tag=None)[source]¶
Bases:
SourceSingle ray source.
- Parameters:
line0 (Line) – starting
- class geoptics.elements.sources.Source(scene=None, tag=None)[source]¶
Bases:
objectSource of rays.
- Parameters:
scene (
Scene) –
- property config¶
Configuration dictionary.
- translate(**kwargs)[source]¶
Translate the source as a whole.
Same syntax and same side effects as
geoptics.elements.vector.Point.translate()Likewise, it is possible to insert a
.copy()to avoid side-effects. FIXME: copy() not implemented yet…return self for convenience
geoptics.elements.vector module¶
Points and vectors in 2D.
- class geoptics.elements.vector.Point(x=None, y=None)[source]¶
Bases:
object2D point.
- property config¶
Configuration dictionary.
- classmethod from_config(config)[source]¶
Alternate constructor.
Examples
>>> v1 = Point(10, 20) >>> config = v1.config >>> v2 = Point.from_config(config) >>> v2.config == config True
- translate(dv=None, dx=0, dy=0)[source]¶
Translate the point.
The translation must be given as a single vector (
dv) or withdxand/ordy. Ifdvis given,dxanddyare discarded.For example:
>>> p = Point(30, 50) >>> dv = Vector(x=10, y=20) >>> p.translate(dv) Point(40, 70)
is the same as:
>>> p = Point(30, 50) >>> p.translate(dx=10, dy=20) Point(40, 70)
- It is possible to change only one coordinate
>>> p = Point(30, 50) >>> p.translate(dx=10) Point(40, 50)
Beware that the transformation is done in-place. this can lead to side effects. For example, in order to leave p1 untouched, a .copy() has to be inserted:
>>> p2 = p.copy().translate(dx=10, dy=20)
- x¶
- y¶
- class geoptics.elements.vector.Vector(x, y)[source]¶
Bases:
object2D Vector.
- property config¶
Configuration dictionary.
- classmethod from_config(config)[source]¶
Alternate constructor.
- Parameters:
config (dict) – Configuration dictionary
- Returns:
new Vector instance
- Return type:
Examples
>>> v1 = Vector(10, 20) >>> config = v1.config >>> v2 = Vector.from_config(config) >>> v2.config == config True
- normalize()[source]¶
Normalize vector (divide it by its norm.
The normalization is done in-place, but also return self, for convenience.
- x¶
- y¶