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:
-
class
geom3d.degrees.
Coordinates
(lat: 'float', lon: 'float')¶ -
to_xy_point
(planet: geom3d.degrees.planets.Planet = <geom3d.degrees.planets.Earth object>) → geom3d.degrees.coordinates.XYPoint¶ This will not have any error.
Although if you wish to convert a series of coordinates, especially in a common reference frame, use
geom3d.degrees.XYPointCollection
instead
-
-
class
geom3d.degrees.
XYPoint
(avg_lat: 'float', x: 'float', y: 'float', parent_collection: 'tp.Optional[XYPointCollection]' = None)¶ -
distance
(other: Union[geom3d.basic.Vector, geom3d.degrees.coordinates.XYPoint]) → float¶ Calculate distance to the other point or vector
-
to_coordinates
(planet: geom3d.degrees.planets.Planet = <geom3d.degrees.planets.Earth object>) → geom3d.degrees.coordinates.Coordinates¶ Convert back to coordinates
-
to_vector
() → geom3d.basic.Vector¶ Convert self into a vector. The z axis will be set to zero.
-
-
class
geom3d.degrees.
XYPointCollection
(coords: List[geom3d.degrees.coordinates.Coordinates], planet: geom3d.degrees.planets.Planet = <geom3d.degrees.planets.Earth object>)¶ A tool to convert a set of coordinates to (x,y) grid.
Put here the coordinates which you will consider in a common frame of reference
This will introduce an error at the x coordinate, amount of which can be calculated from
geom3d.degrees.XYPointCollection.maximum_latitudinal_error_per_degree
andgeom3d.degrees.XYPointCollection.maximum_absolute_error
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!
-
class
geom3d.degrees.
Planet
¶
-
class
geom3d.degrees.
Earth
¶
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) → Generator[Tuple[geom3d.basic.Box, geom3d.basic.Box], None, None]¶ Return all intersections of these elements that collide.
-
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) → 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.
-
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_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_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¶ 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: geom3d.polygons.twodimensional.Polygon2D, distance_from_start: float)¶ This class serves to compute points that lie somewhere on the polygons’ perimeter, counting as polygon’s vertices were specified
-
advance
(v: float)¶ Move the pointer v ahead
Parameters: v – amount to move the pointer along the perimeter, or a negative value to move it backwards.
-
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
-