Degree and coordinate conversion¶
Sometimes working directly with coordinates in degrees is cumbersome. For example, you have no way to calculate easily distance between two points, or say “this coordinate 2 metres west”.
These routines and objects try to remedy that:
Please note that error introduced by this transformation is the more pronounced the closer you are to the Poles, so no flying over the Poles for you!
Basic structures¶
Note that you first need to set a satisfying epsilon:
-
geom3d.
set_epsilon
(new_epsilon: float)¶ Set a new value of epsilon.
Epsilon is used to compare two floats, and to determine the handness of the vector inside/outside the polygon
Parameters: new_epsilon – new value of epsilon
-
class
geom3d.
Vector
(x: float, y: float, z: float = 0.0)¶ A 3D vector
-
cross_product
(other: geom3d.basic.Vector) → geom3d.basic.Vector¶ Calculate the cross product between this vector and the other
-
dot_product
(other: geom3d.basic.Vector) → float¶ Calculate the dot product between this vector and the other
-
unitize
() → geom3d.basic.Vector¶ Return an unit vector having the same heading as current vector
-
classmethod
zero
() → geom3d.basic.Vector¶ Return a (0, 0, 0) point
-
zero_z
() → geom3d.basic.Vector¶ Return self, but with z coordinate zeroed
-
-
class
geom3d.
Line
(start: Vector, stop: Vector)¶ A line in 3D. It starts somewhere and ends somewhere.
Parameters: - start – where does the line start
- stop – where does the line end
-
get_point
(distance_from_start: float) → geom3d.basic.PointInLine¶ Get a point that lies on this line some distance from the start
Parameters: distance_from_start – the distance from the start
-
get_points_along
(step: float, include_last_point: bool = False) → Iterator[geom3d.basic.Vector]¶ Return a list of vectors corresponding to equally-spaced points on this line
Parameters: - step – next vector will be distant by exactly this from the previous one
- include_last_point – whether to include last point. Distance from the almost last to last might not be equal to step
-
length
¶ Return the length of this line
-
unit_vector
¶ Return a unit vector corresponding to the direction of this line.
-
class
geom3d.
PointInLine
(line: geom3d.basic.Line, distance_from_start: float)¶ This class serves to compute points that lie a certain distance from the start, but still lie on this line.
-
length
¶ The distance from the start of the line
-
to_vector
() → geom3d.basic.Vector¶ Return the physical point given PointInLine corresponds to
-
-
class
geom3d.
Path
(size: Optional[geom3d.basic.Vector] = None, points: Optional[List[geom3d.basic.Vector]] = None)¶ -
advance
(delta: geom3d.basic.Vector)¶ Place next segment of the path at given difference from current head
-
classmethod
from_to
(source: geom3d.basic.Vector, destination: geom3d.basic.Vector, size: geom3d.basic.Vector, step: Optional[float] = None)¶ Get a path from a point to other point with particular _size
Points will be placed each _size/2 if a vector is given, otherwise each size_of_step distance.
-
get_intersecting_boxes
(other: geom3d.paths.path.Path) → Generator[Tuple[geom3d.basic.Box, geom3d.basic.Box], None, None]¶ Return all intersections of these elements that collide.
-
head_towards
(point: geom3d.basic.Vector, delta: float)¶ Place next pieces of the path at delta distances going towards the point. The last segment may be shorter
Parameters: - point – point to advance towards
- delta – size of step to use in constructing the path
-
Polygons¶
-
class
geom3d.polygons.
Polygon2D
(points: List[geom3d.basic.Vector])¶ A polygon that disregards the z axis
-
centroid
¶ Return the center of mass for this polygon
-
downscale
(step: float) → geom3d.polygons.twodimensional.Polygon2D¶ Make a smaller polygon by moving each vertex by step inside the polygon.
Parameters: step – distance to which move each vertex Raises: ValueError – polygon cannot be shrunk further
-
get_next_segment
(segment: geom3d.basic.Line) → geom3d.basic.Line¶ Return the next segment in regards to the one currently passed
-
get_nth_segment
(segment: geom3d.basic.Line, n: int) → geom3d.basic.Line¶ Get n-th segment in regards to the one currently passed in
-
get_point_on_polygon
(distance_from_start: float, offset: float = 0) → geom3d.polygons.twodimensional.PointOnPolygon2D¶ Return a point somewhere on the perimeter of this polygon
Parameters: - distance_from_start – distance from the first point of this polygon. Can be negative, in which case we will count backwards.
- offset – offset to add in while calculating the distance. This value is fixed.
-
get_point_on_polygon_relative
(**kwargs)¶ Return a point on polygon counted as a fraction of it’s total perimeter.
Eg. 0.5 will get you a point on polygon directly at half of it’s perimeter.
Parameters: - distance_from_start – fraction of polygon’s total perimeter. Must be greater or equal than zero, must be less than 1
- offset – offset to use, also a fraction of polygon’s total length
-
get_points_along
(step: float, include_last_point: bool = False) → Iterator[geom3d.basic.Vector]¶ Return a list of vectors corresponding to equally-spaced points on this line
Parameters: - step – the distance between two consecutive points
- include_last_point – whether to include last point. Distance from the almost last to last might not be equal to step
-
get_previous_segment
(segment: geom3d.basic.Line) → geom3d.basic.Line¶ Return the previous segment in regards to the one currently passed
-
get_segment_at_distance
(offset: float) → geom3d.basic.Line¶ Return the segment backing some distance along the polygon’s perimeter
Parameters: offset – the distance to travel to get the polygon’s segment. If this appears directly on a vertex, the segment which starts at this vertex will be returned.
-
get_signed_area
() → float¶ Area of this polygon as calculated by the shoelace formula
-
get_surface_area
() → float¶ Return the surface area of this polygon
-
iter_from
(offset: float = 0) → Iterator[geom3d.basic.Vector]¶ Return all points that this polygon consists of, but starting from offset
Parameters: offset – length from start from where to start counting. The next vertex specified will come in first. If the offset is directly on a vertex, this vertex will be returned.
-
iter_segments
() → Iterator[geom3d.basic.Line]¶ Get all segments
Returns: an iterator, yielding subsequent segments of this polygon
-
to_path
(step: float, size: geom3d.basic.Vector) → geom3d.paths.path.Path¶ Return a path flying around the perimeter of this polygon
Parameters: - step – step to which advance the path with
- size – size of the box that will determine the path
-
-
class
geom3d.polygons.
PointOnPolygon2D
(polygon: 'Polygon2D', _distance_from_start: 'float', offset: 'float' = 0)¶ -
advance
(v: float)¶ Move the pointer v ahead.
The only routine to move inside the polygon at all
Parameters: v – amount to move the pointer along the perimeter, or a negative value to move it backwards.
-
get_segment_and_vector
() → Tuple[geom3d.basic.Line, geom3d.basic.Vector]¶ Return both the vector (as in
to_vector()
) and the segment on which it lies.Returns: a tuple of (Line - the segment, Vector - coordinates of this point)
-
get_unit_vector_away_polygon
() → geom3d.basic.Vector¶ Return exactly the opposite vector that
get_unit_vector_towards_polygon()
would return
-
get_unit_vector_towards_polygon
() → geom3d.basic.Vector¶ Get a unit vector, that if applied to self.to_vector() would direct us inside the polygon
-
is_on_vertex
() → bool¶ Does this point occur right on a vertex of the polygon?
-
to_vector
() → geom3d.basic.Vector¶ Returns the coordinates of the point on the perimeter.
The point will lie precisely on the perimeter
-
Note that PointOnPolygon2D will behave correctly when faced with calculating the vector towards the polygon then such point occurs on the vertex. It will take the average of two segment’s unit vectors into consideration in that case.
More complex 3D structures¶
-
class
geom3d.meshes.
Triangle
(a: Vector, b: Vector, c: Vector)¶ A triangle defined by it’s 3 vertices
-
get_edges
() → Tuple[geom3d.basic.Line, geom3d.basic.Line, geom3d.basic.Line]¶ Return edges of this triangle
-
get_edges_length
() → Tuple[float, float, float]¶ Return lengths of edges corresponding to n-th edge
-
get_perimeter_length
() → float¶ Return the length of triangle’s perimeter
-
get_surface_area
() → float¶ Return the surface area of this triangle
-