A Python wrapper for the NAIF CSPICE Toolkit providing essential tools for spacecraft navigation and planetary science calculations
Linear algebra functions for vector operations, matrix manipulations, and mathematical computations commonly used in space geometry. These functions provide the mathematical foundation for coordinate transformations and geometric calculations.
Basic vector arithmetic and analysis functions.
def vadd(v1: ndarray, v2: ndarray) -> ndarray:
"""
Add two vectors.
Parameters:
- v1: ndarray, first vector
- v2: ndarray, second vector
Returns:
ndarray: sum vector v1 + v2
"""
def vsub(v1: ndarray, v2: ndarray) -> ndarray:
"""
Subtract two vectors.
Parameters:
- v1: ndarray, first vector
- v2: ndarray, second vector
Returns:
ndarray: difference vector v1 - v2
"""
def vdot(v1: ndarray, v2: ndarray) -> float:
"""
Compute dot product of two vectors.
Parameters:
- v1: ndarray, first vector
- v2: ndarray, second vector
Returns:
float: dot product v1 • v2
"""
def vcrss(v1: ndarray, v2: ndarray) -> ndarray:
"""
Compute cross product of two vectors.
Parameters:
- v1: ndarray, first vector
- v2: ndarray, second vector
Returns:
ndarray: cross product vector v1 × v2
"""
def vnorm(v: ndarray) -> float:
"""
Compute vector magnitude (norm).
Parameters:
- v: ndarray, input vector
Returns:
float: vector magnitude ||v||
"""
def vhat(v: ndarray) -> ndarray:
"""
Compute unit vector.
Parameters:
- v: ndarray, input vector
Returns:
ndarray: unit vector v/||v||
"""
def vscl(s: float, v: ndarray) -> ndarray:
"""
Scale vector by scalar.
Parameters:
- s: float, scaling factor
- v: ndarray, input vector
Returns:
ndarray: scaled vector s*v
"""Matrix arithmetic and transformation functions.
def mxm(m1: ndarray, m2: ndarray) -> ndarray:
"""
Multiply two matrices.
Parameters:
- m1: ndarray, first matrix
- m2: ndarray, second matrix
Returns:
ndarray: product matrix m1 * m2
"""
def mxv(m: ndarray, v: ndarray) -> ndarray:
"""
Multiply matrix by vector.
Parameters:
- m: ndarray, matrix
- v: ndarray, vector
Returns:
ndarray: product vector m * v
"""
def mtxv(m: ndarray, v: ndarray) -> ndarray:
"""
Multiply transpose of matrix by vector.
Parameters:
- m: ndarray, matrix
- v: ndarray, vector
Returns:
ndarray: product vector m^T * v
"""
def xpose(m: ndarray) -> ndarray:
"""
Transpose a 3x3 matrix.
Parameters:
- m: ndarray, 3x3 matrix
Returns:
ndarray: transposed matrix
"""
def invert(m: ndarray) -> ndarray:
"""
Invert a matrix.
Parameters:
- m: ndarray, input matrix
Returns:
ndarray: inverted matrix
"""import spiceypy as spice
import numpy as np
# Define two vectors
v1 = np.array([1.0, 2.0, 3.0])
v2 = np.array([4.0, 5.0, 6.0])
# Basic operations
sum_vec = spice.vadd(v1, v2)
dot_product = spice.vdot(v1, v2)
cross_product = spice.vcrss(v1, v2)
magnitude = spice.vnorm(v1)
unit_vector = spice.vhat(v1)
print(f"Sum: {sum_vec}")
print(f"Dot product: {dot_product}")
print(f"Cross product: {cross_product}")
print(f"Magnitude: {magnitude:.3f}")
print(f"Unit vector: {unit_vector}")# Create rotation matrix and apply to vector
angle = spice.rpd() * 45 # 45 degrees in radians
rotation_matrix = spice.rotate(angle, 3) # Rotate about Z-axis
vector = np.array([1.0, 0.0, 0.0])
rotated_vector = spice.mxv(rotation_matrix, vector)
print(f"Rotated vector: {rotated_vector}")Install with Tessl CLI
npx tessl i tessl/pypi-spiceypydocs