Geometry Module
This module contains classes for representing 3D shapes.
- class Vector3D(x: float, y: float, z: float)[source]
Represents a vector in 3D space.
Initialize a new vector.
- Parameters:
- classmethod create_random() Vector3D[source]
Create a random vector.
- Returns:
A random vector.
- Return type:
- length() float[source]
Calculate the length of this vector.
- Returns:
The length of this vector.
- Return type:
- normalize() Vector3D[source]
Normalize this vector.
- Returns:
A new vector with the same direction as this vector but with unit length.
- Return type:
- cross(other: Vector3D) Vector3D[source]
Calculate the cross product of this vector with another vector.
- class Point2D(x: float, y: float)[source]
Represents a point in 2D space.
Initialize a new point.
- class Point3D(x: float, y: float, z: float)[source]
Represents a point in 3D space.
Initialize a new point.
- Parameters:
- calculate_distance(other: Point3D) float[source]
Calculate the distance between this point and another point.
- midpoint(other: Point3D) Point3D[source]
Calculate the midpoint between this point and another point.
- gram_schmidt(n: Vector3D) Tuple[Vector3D, Vector3D][source]
Generate two orthogonal vectors for a given vector using the Gram-Schmidt process.
- class CylinderCapType(value)[source]
The type of a cap.
- Variables:
NO_CAP – No cap.
FLAT – Flat cap.
ROUND – Round cap.
- class Cylinder(start: Point3D, end: Point3D, radius: float, cap_type: CylinderCapType)[source]
A cylinder.
- Parameters:
start (Point3D) – The start point of the cylinder.
end (Point3D) – The end point of the cylinder.
radius (float) – The radius of the cylinder.
cap_type (CylinderCapType) – The type of the cap.
- same_side_of_plane(plane: Plane3D, p1: Point3D, p2: Point3D) bool[source]
Check if two points are on the same side of a plane.
- distance_to_line(line: Line3D, point: Point3D) float[source]
Compute the distance from a point to the line.
- get_perpendicular_lines(line: Line3D, width: float, num_lines: int) List[Line3D][source]
Split current line into multiple perpendicular lines.
- Parameters:
- Returns:
The perpendicular lines.
- Return type:
ty.List[Line3D]
- Raises:
ValueError – If the number of lines is less than 1.
ValueError – If the width is less than or equal to 0.
- get_points_on_line_3d(line: Line3D, num_points: int) List[Point3D][source]
Generate num_points + 1 points along a line.
- get_points_on_circumference_circle_3d(circle: Circle3D, num_points: int) List[Point3D][source]
Generate points on the circumference of the circle.
- get_points_on_surface_circle_3d(circle: Circle3D, num_radii: int, num_points: int) List[Point3D][source]
Generate points on the surface of the circle.
- get_points_on_surface_sphere(sphere: Sphere, num_phi: int, num_theta: int, filter_for_pov: bool = True) List[Point3D][source]
Generate points on the surface of a sphere.
- Parameters:
sphere (Sphere) – The sphere.
num_phi (int) – The resolution of the sphere in the phi direction.
num_theta (int) – The resolution of the sphere in the theta direction.
filter_for_pov (bool) – If True, only return points that are on the surface of the sphere we can see from POV positive z-axis towards origin.
- Returns:
The points on the surface of the sphere.
- Return type:
ty.List[Point3D]
- get_points_on_surface_cap(cap_type: CylinderCapType, center_cap: Point3D, radius_cap: float, normal_cap: Vector3D, center_cylinder: Point3D, resolution: int, filter_for_pov: bool = True) List[Point3D][source]
Generate points on the surface of the cap.
- Parameters:
cap_type (CylinderCapType) – The type of the cap.
center_cap (Point3D) – The center of the cap.
radius_cap (float) – The radius of the cap.
normal_cap (Vector3D) – The normal vector of the cap.
center_cylinder (Point3D) – The center of the cylinder.
resolution (int) – The resolution of the cap.
filter_for_pov (bool) – If True, only return points that are on the visible surface of the cap (i.e. the surface of the cap we can see from POV positive z-axis towards origin).
- Returns:
The points on the surface of the cap.
- Return type:
ty.List[Point3D]
- Raises:
ValueError – If the cap type is unknown.
- get_points_on_surface_cylinder(cylinder: Cylinder, resolution: int) List[Point3D][source]
Generate points on the surface of the cylinder.
- point_is_inside_sphere(sphere: Sphere, point: Point3D) bool[source]
Check if a point is inside the sphere.
- point_is_inside_cylinder(cylinder: Cylinder, point: Point3D) bool[source]
Check if a point is inside the cylinder.
- Parameters:
- Returns:
True if the point is inside the cylinder, False otherwise.
- Return type:
- Raises:
ValueError – If the cap type is unknown.
- sphere_intersects_with_sphere(sphere1: Sphere, sphere2: Sphere) bool[source]
Check if two spheres intersect.