Geometric Operations
Face Properties
AsteroidShapeModels.face_center
— Functionface_center(vs::StaticVector{3, <:StaticVector{3}}) -> StaticVector{3}
face_center(v1::StaticVector{3}, v2::StaticVector{3}, v3::StaticVector{3}) -> StaticVector{3}
Calculate the center (centroid) of a triangular face.
Arguments
vs
: A static vector containing three vertices of the trianglev1
,v2
,v3
: Three vertices of the triangle
Returns
StaticVector{3}
: The center point of the triangle, computed as the arithmetic mean of the three vertices
Examples
v1 = SA[1.0, 0.0, 0.0]
v2 = SA[0.0, 1.0, 0.0]
v3 = SA[0.0, 0.0, 1.0]
center = face_center(v1, v2, v3) # Returns SA[1/3, 1/3, 1/3]
AsteroidShapeModels.face_normal
— Functionface_normal(vs::StaticVector{3, <:StaticVector{3}}) -> StaticVector{3}
face_normal(v1::StaticVector{3}, v2::StaticVector{3}, v3::StaticVector{3}) -> StaticVector{3}
Calculate the unit normal vector of a triangular face.
Arguments
vs
: A static vector containing three vertices of the trianglev1
,v2
,v3
: Three vertices of the triangle in counter-clockwise order
Returns
StaticVector{3}
: The unit normal vector pointing outward from the face (following right-hand rule)
Notes
The normal direction follows the right-hand rule based on the vertex ordering. For a counter-clockwise vertex ordering when viewed from outside, the normal points outward.
Examples
v1 = SA[1.0, 0.0, 0.0]
v2 = SA[0.0, 1.0, 0.0]
v3 = SA[0.0, 0.0, 0.0]
normal = face_normal(v1, v2, v3) # Returns SA[0.0, 0.0, 1.0]
AsteroidShapeModels.face_area
— Functionface_area(vs::StaticVector{3, <:StaticVector{3}}) -> Real
face_area(v1::StaticVector{3}, v2::StaticVector{3}, v3::StaticVector{3}) -> Real
Calculate the area of a triangular face.
Arguments
vs
: A static vector containing three vertices of the trianglev1
,v2
,v3
: Three vertices of the triangle
Returns
Real
: The area of the triangle
Notes
The area is computed using the cross product formula: area = ||(v2 - v1) × (v3 - v2)|| / 2
Examples
# Unit right triangle
v1 = SA[0.0, 0.0, 0.0]
v2 = SA[1.0, 0.0, 0.0]
v3 = SA[0.0, 1.0, 0.0]
area = face_area(v1, v2, v3) # Returns 0.5
Shape Properties
AsteroidShapeModels.polyhedron_volume
— Functionpolyhedron_volume(nodes, faces) -> Float64
polyhedron_volume(shape::ShapeModel) -> Float64
Calculate the volume of a polyhedron using the divergence theorem.
Arguments
nodes
: Array of vertex positionsfaces
: Array of triangular face definitions (vertex indices)shape::ShapeModel
: A shape model containing nodes and faces
Returns
Float64
: Volume of the polyhedron
Notes
The volume is computed using the formula: V = (1/6) * Σ (A × B) · C
where A, B, C are the vertices of each triangular face. The shape must be a closed polyhedron with consistently oriented faces.
Examples
# Unit cube
nodes = [SA[0,0,0], SA[1,0,0], SA[1,1,0], SA[0,1,0],
SA[0,0,1], SA[1,0,1], SA[1,1,1], SA[0,1,1]]
faces = [SA[1,2,3], SA[1,3,4], ...] # Define all 12 triangular faces
vol = polyhedron_volume(nodes, faces) # Returns 1.0
AsteroidShapeModels.equivalent_radius
— Functionequivalent_radius(VOLUME::Real) -> Float64
equivalent_radius(shape::ShapeModel) -> Float64
Calculate the radius of a sphere with the same volume as the given volume or shape.
Arguments
VOLUME::Real
: Volume of the objectshape::ShapeModel
: A shape model to calculate volume from
Returns
Float64
: Radius of the equivalent sphere
Notes
The equivalent radius is calculated as: r = (3V/4π)^(1/3)
Examples
# Sphere with radius 2
volume = 4π/3 * 2^3
r_eq = equivalent_radius(volume) # Returns 2.0
# From shape model
shape = load_shape_obj("asteroid.obj")
r_eq = equivalent_radius(shape)
AsteroidShapeModels.maximum_radius
— Functionmaximum_radius(nodes) -> Float64
maximum_radius(shape::ShapeModel) -> Float64
Calculate the maximum distance from the origin to any vertex.
Arguments
nodes
: Array of vertex positionsshape::ShapeModel
: A shape model containing nodes
Returns
Float64
: Maximum distance from origin to any vertex
Notes
This represents the radius of the smallest sphere centered at the origin that contains all vertices of the shape.
Examples
nodes = [SA[1,0,0], SA[0,2,0], SA[0,0,3]]
r_max = maximum_radius(nodes) # Returns 3.0
AsteroidShapeModels.minimum_radius
— Functionminimum_radius(nodes) -> Float64
minimum_radius(shape::ShapeModel) -> Float64
Calculate the minimum distance from the origin to any vertex.
Arguments
nodes
: Array of vertex positionsshape::ShapeModel
: A shape model containing nodes
Returns
Float64
: Minimum distance from origin to any vertex
Notes
This represents the radius of the largest sphere centered at the origin that fits entirely inside the convex hull of the vertices.
Examples
nodes = [SA[1,0,0], SA[0,2,0], SA[0,0,3]]
r_min = minimum_radius(nodes) # Returns 1.0
Angle Calculations
AsteroidShapeModels.angle_rad
— Functionangle_rad(v1, v2) -> Float64
Calculate the angle between two vectors in radians.
Arguments
v1
: First vectorv2
: Second vector
Returns
- Angle between vectors in radians [0, π]
angle_rad(v1::AbstractVector{<:AbstractVector}, v2::AbstractVector{<:AbstractVector}) -> Vector{Float64}
Calculate angles between corresponding pairs of vectors in two arrays (broadcast version).
Arguments
v1
: Array of first vectorsv2
: Array of second vectors (must have same length as v1)
Returns
- Array of angles in radians between corresponding vector pairs
Examples
v1s = [SA[1,0,0], SA[0,1,0]]
v2s = [SA[0,1,0], SA[1,0,0]]
angles = angle_rad(v1s, v2s) # Returns [π/2, π/2]
AsteroidShapeModels.angle_deg
— Functionangle_deg(v1, v2) -> Float64
Calculate the angle between two vectors in degrees.
Arguments
v1
: First vectorv2
: Second vector
Returns
- Angle between vectors in degrees [0, 180]
angle_deg(v1::AbstractVector{<:AbstractVector}, v2::AbstractVector{<:AbstractVector}) -> Vector{Float64}
Calculate angles between corresponding pairs of vectors in two arrays (broadcast version).
Arguments
v1
: Array of first vectorsv2
: Array of second vectors (must have same length as v1)
Returns
- Array of angles in degrees between corresponding vector pairs
Examples
v1s = [SA[1,0,0], SA[0,1,0]]
v2s = [SA[0,1,0], SA[1,0,0]]
angles = angle_deg(v1s, v2s) # Returns [90.0, 90.0]
AsteroidShapeModels.solar_phase_angle
— Functionsolar_phase_angle(sun, target, observer) -> Float64
Calculate a sun-target-observer angle (phase angle).
Arguments
sun
: Sun position vectortarget
: Target position vectorobserver
: Observer position vector
Returns
- ∠STO : Sun-target-observer angle (phase angle) [rad]
AsteroidShapeModels.solar_elongation_angle
— Functionsolar_elongation_angle(sun, observer, target) -> Float64
Calculate a sun-observer-target angle (solar elongation angle).
Arguments
sun
: Sun position vectorobserver
: Observer position vectortarget
: Target position vector
Returns
- ∠SOT : Sun-observer-target angle (solar elongation angle) [rad]