or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

ck-orientation.mdcoordinate-systems.mddata-structures.mddsk-shape-models.mde-kernels.mdephemeris-trajectories.mderror-handling.mdevent-finding.mdgeometry-surface.mdindex.mdkernel-management.mdlow-level-file-access.mdphysical-constants.mdreference-frames.mdspacecraft-clock.mdtime-systems.mdvector-matrix.md

vector-matrix.mddocs/

0

# Vector and Matrix Mathematics

1

2

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.

3

4

## Capabilities

5

6

### Vector Operations

7

8

Basic vector arithmetic and analysis functions.

9

10

```python { .api }

11

def vadd(v1: ndarray, v2: ndarray) -> ndarray:

12

"""

13

Add two vectors.

14

15

Parameters:

16

- v1: ndarray, first vector

17

- v2: ndarray, second vector

18

19

Returns:

20

ndarray: sum vector v1 + v2

21

"""

22

23

def vsub(v1: ndarray, v2: ndarray) -> ndarray:

24

"""

25

Subtract two vectors.

26

27

Parameters:

28

- v1: ndarray, first vector

29

- v2: ndarray, second vector

30

31

Returns:

32

ndarray: difference vector v1 - v2

33

"""

34

35

def vdot(v1: ndarray, v2: ndarray) -> float:

36

"""

37

Compute dot product of two vectors.

38

39

Parameters:

40

- v1: ndarray, first vector

41

- v2: ndarray, second vector

42

43

Returns:

44

float: dot product v1 • v2

45

"""

46

47

def vcrss(v1: ndarray, v2: ndarray) -> ndarray:

48

"""

49

Compute cross product of two vectors.

50

51

Parameters:

52

- v1: ndarray, first vector

53

- v2: ndarray, second vector

54

55

Returns:

56

ndarray: cross product vector v1 × v2

57

"""

58

59

def vnorm(v: ndarray) -> float:

60

"""

61

Compute vector magnitude (norm).

62

63

Parameters:

64

- v: ndarray, input vector

65

66

Returns:

67

float: vector magnitude ||v||

68

"""

69

70

def vhat(v: ndarray) -> ndarray:

71

"""

72

Compute unit vector.

73

74

Parameters:

75

- v: ndarray, input vector

76

77

Returns:

78

ndarray: unit vector v/||v||

79

"""

80

81

def vscl(s: float, v: ndarray) -> ndarray:

82

"""

83

Scale vector by scalar.

84

85

Parameters:

86

- s: float, scaling factor

87

- v: ndarray, input vector

88

89

Returns:

90

ndarray: scaled vector s*v

91

"""

92

```

93

94

### Matrix Operations

95

96

Matrix arithmetic and transformation functions.

97

98

```python { .api }

99

def mxm(m1: ndarray, m2: ndarray) -> ndarray:

100

"""

101

Multiply two matrices.

102

103

Parameters:

104

- m1: ndarray, first matrix

105

- m2: ndarray, second matrix

106

107

Returns:

108

ndarray: product matrix m1 * m2

109

"""

110

111

def mxv(m: ndarray, v: ndarray) -> ndarray:

112

"""

113

Multiply matrix by vector.

114

115

Parameters:

116

- m: ndarray, matrix

117

- v: ndarray, vector

118

119

Returns:

120

ndarray: product vector m * v

121

"""

122

123

def mtxv(m: ndarray, v: ndarray) -> ndarray:

124

"""

125

Multiply transpose of matrix by vector.

126

127

Parameters:

128

- m: ndarray, matrix

129

- v: ndarray, vector

130

131

Returns:

132

ndarray: product vector m^T * v

133

"""

134

135

def xpose(m: ndarray) -> ndarray:

136

"""

137

Transpose a 3x3 matrix.

138

139

Parameters:

140

- m: ndarray, 3x3 matrix

141

142

Returns:

143

ndarray: transposed matrix

144

"""

145

146

def invert(m: ndarray) -> ndarray:

147

"""

148

Invert a matrix.

149

150

Parameters:

151

- m: ndarray, input matrix

152

153

Returns:

154

ndarray: inverted matrix

155

"""

156

```

157

158

## Common Usage Patterns

159

160

### Vector Analysis

161

```python

162

import spiceypy as spice

163

import numpy as np

164

165

# Define two vectors

166

v1 = np.array([1.0, 2.0, 3.0])

167

v2 = np.array([4.0, 5.0, 6.0])

168

169

# Basic operations

170

sum_vec = spice.vadd(v1, v2)

171

dot_product = spice.vdot(v1, v2)

172

cross_product = spice.vcrss(v1, v2)

173

magnitude = spice.vnorm(v1)

174

unit_vector = spice.vhat(v1)

175

176

print(f"Sum: {sum_vec}")

177

print(f"Dot product: {dot_product}")

178

print(f"Cross product: {cross_product}")

179

print(f"Magnitude: {magnitude:.3f}")

180

print(f"Unit vector: {unit_vector}")

181

```

182

183

### Matrix Transformations

184

```python

185

# Create rotation matrix and apply to vector

186

angle = spice.rpd() * 45 # 45 degrees in radians

187

rotation_matrix = spice.rotate(angle, 3) # Rotate about Z-axis

188

189

vector = np.array([1.0, 0.0, 0.0])

190

rotated_vector = spice.mxv(rotation_matrix, vector)

191

print(f"Rotated vector: {rotated_vector}")

192

```