Collection of KSP/Unity related mathematical functions.
Represents the rotation from an initial coordinate system when looking down the z-axis and "up" being the y-axis
Name | Type | Read-only | Description |
---|---|---|---|
angle | float | R/O | The rotation angle around the axis in degrees |
axis | ksp::math::Vec3 | R/O | The rotation axis |
euler | ksp::math::Vec3 | R/W | Euler angles in degree of the rotation |
inverse | ksp::math::Direction | R/O | Inverse direction |
pitch | float | R/O | Pitch in degree |
right_vector | ksp::math::Vec3 | R/O | Right vector of the rotation |
roll | float | R/O | Roll in degree |
up_vector | ksp::math::Vec3 | R/O | Up vector of the rotation |
vector | ksp::math::Vec3 | R/W | Fore vector of the rotation (i.e. looking/facing direction |
yaw | float | R/O | Yaw in degree |
direction.to_global ( frame : ksp::math::TransformFrame ) -> ksp::math::GlobalDirection
Associate this direction with a coordinate system
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
direction.to_string ( ) -> string
Convert the direction to string
An angular velocity in space, that can be projected to a 3-dimensional vector in a specific frame of reference
globalangularvelocity.relative_to ( frame : ksp::math::TransformFrame ) -> ksp::math::GlobalVector
Get relative angular velocity to a frame of reference
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
globalangularvelocity.to_fixed ( frame : ksp::math::TransformFrame,
decimals : int ) -> string
Convert angular velocity to string with fixed number of decimals
in a given coordinate system.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference | |
decimals | int | Number of decimals |
globalangularvelocity.to_local ( frame : ksp::math::TransformFrame ) -> ksp::math::Vec3
Get local angular velocity in a frame of reference
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
globalangularvelocity.to_string ( frame : ksp::math::TransformFrame ) -> string
Convert angular velocity to string in a given coordinate system.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
Represents the rotation from an initial coordinate system when looking down the z-axis and "up" being the y-axis
Name | Type | Read-only | Description |
---|---|---|---|
right_vector | ksp::math::GlobalVector | R/O | Right vector of the rotation |
up_vector | ksp::math::GlobalVector | R/O | Up vector of the rotation |
vector | ksp::math::GlobalVector | R/W | Fore vector of the rotation (i.e. looking/facing direction |
globaldirection.euler ( frame : ksp::math::TransformFrame ) -> ksp::math::Vec3
Get euler angles in a specific coordinate system
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
globaldirection.pitch ( frame : ksp::math::TransformFrame ) -> float
Get pitch angle in a specific coordinate system
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
globaldirection.roll ( frame : ksp::math::TransformFrame ) -> float
Get roll angle in a specific coordinate system
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
globaldirection.to_local ( frame : ksp::math::TransformFrame ) -> ksp::math::Direction
Get local direction in a coordinate system
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
globaldirection.to_string ( frame : ksp::math::TransformFrame ) -> string
Convert the direction to string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
globaldirection.yaw ( frame : ksp::math::TransformFrame ) -> float
Get yaw angle in a specific coordinate system
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
A position in space that can be projected to a 3-dimensional vector in a specific coordinate system
globalposition.distance ( other : ksp::math::GlobalPosition ) -> float
Calculate the distance of other
position.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::GlobalPosition | Other position |
globalposition.distance_sqr ( other : ksp::math::GlobalPosition ) -> float
Calculate the squared distance of other
position.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::GlobalPosition | Other position |
globalposition.lerp_to ( other : ksp::math::GlobalPosition,
t : float ) -> ksp::math::GlobalPosition
Linear interpolate position between this and other
position, where t = 0.0
is this and t = 1.0
is other
.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::GlobalPosition | Other position | |
t | float | Relative position of mid-point (0.0 - 1.0) |
globalposition.to_fixed ( frame : ksp::math::TransformFrame,
decimals : int ) -> string
Convert the vector to string with fixed number of decimals
in a given coordinate system.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference | |
decimals | int | Number of decimals |
globalposition.to_local ( frame : ksp::math::TransformFrame ) -> ksp::math::Vec3
Get local vector in a coordinate system
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
globalposition.to_string ( frame : ksp::math::TransformFrame ) -> string
Convert vector to string in a given coordinate system.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
Abstract vector in space that can be projected to a concrete 3-dimensional vector in a specific coordinate system
Name | Type | Read-only | Description |
---|---|---|---|
magnitude | float | R/O | Magnitude/length of the vector |
normalized | ksp::math::GlobalVector | R/O | Normalized vector (i.e. scaled to length 1) |
sqr_magnitude | float | R/O | Squared magnitude of the vector |
globalvector.cross ( other : ksp::math::GlobalVector ) -> ksp::math::GlobalVector
Calculate the cross/other product with other
vector.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::GlobalVector | Other vector |
globalvector.dot ( other : ksp::math::GlobalVector ) -> float
Calculate the dot/inner product with other
vector.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::GlobalVector | Other vector |
globalvector.exclude_from ( other : ksp::math::GlobalVector ) -> ksp::math::GlobalVector
Exclude this from other
vector.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::GlobalVector | Other vector |
globalvector.lerp_to ( other : ksp::math::GlobalVector,
t : float ) -> ksp::math::GlobalVector
Linear interpolate position between this and other
vector, where t = 0.0
is this and t = 1.0
is other
.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::GlobalVector | Other vector | |
t | float | Relative position of mid-point (0.0 - 1.0) |
globalvector.to_direction ( ) -> ksp::math::GlobalDirection
Convert the vector to a rotation/direction in space.
globalvector.to_fixed ( frame : ksp::math::TransformFrame,
decimals : int ) -> string
Convert the vector to string with fixed number of decimals
in a given coordinate system.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference | |
decimals | int | Number of decimals |
globalvector.to_local ( frame : ksp::math::TransformFrame ) -> ksp::math::Vec3
Get local vector in a coordinate system
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
globalvector.to_string ( frame : ksp::math::TransformFrame ) -> string
Convert vector to string in a given coordinate system.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
A velocity in space, that can be projected to a 3-dimensional vector in a specific frame of reference
Name | Type | Read-only | Description |
---|---|---|---|
position | ksp::math::GlobalPosition | R/W | Position the velocity was measured at |
vector | ksp::math::GlobalVector | R/W | Relative velocity vector |
globalvelocity.to_fixed ( frame : ksp::math::TransformFrame,
decimals : int ) -> string
Convert the vector to string with fixed number of decimals
in a given coordinate system.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference | |
decimals | int | Number of decimals |
globalvelocity.to_local ( frame : ksp::math::TransformFrame ) -> ksp::math::Vec3
Get local velocity in a frame of reference
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
globalvelocity.to_relative ( frame : ksp::math::TransformFrame ) -> ksp::math::GlobalVector
Get relative velocity to frame of reference
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
globalvelocity.to_string ( frame : ksp::math::TransformFrame ) -> string
Convert vector to string in a given coordinate system.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
A 2-dimensional matrix.
Name | Type | Read-only | Description |
---|---|---|---|
a | float | R/O | a |
b | float | R/O | b |
c | float | R/O | c |
d | float | R/O | d |
determinant | float | R/O | Get determinant of matrix |
inverse | ksp::math::Matrix2x2 | R/O | Invert matrix |
Representation of a coordinate frame of reference
Name | Type | Read-only | Description |
---|---|---|---|
back | ksp::math::GlobalVector | R/O | backward vector of the coordinate system |
down | ksp::math::GlobalVector | R/O | down vector of the coordinate system |
forward | ksp::math::GlobalVector | R/O | forward vector of the coordinate system |
left | ksp::math::GlobalVector | R/O | left vector of the coordinate system |
right | ksp::math::GlobalVector | R/O | right vector of the coordinate system |
up | ksp::math::GlobalVector | R/O | up vector of the coordinate system |
transformframe.to_local_position ( position : ksp::math::GlobalPosition ) -> ksp::math::Vec3
Get local coordinates of a position
Parameters
Name | Type | Optional | Description |
---|---|---|---|
position | ksp::math::GlobalPosition | Position to transform |
transformframe.to_local_vector ( vector : ksp::math::GlobalVector ) -> ksp::math::Vec3
Get local coordinates of a vector
Parameters
Name | Type | Optional | Description |
---|---|---|---|
vector | ksp::math::GlobalVector | Vector to transform |
transformframe.to_local_velocity ( velocity : ksp::math::GlobalVelocity ) -> ksp::math::Vec3
Get local coordinates of a velocity
Parameters
Name | Type | Optional | Description |
---|---|---|---|
velocity | ksp::math::GlobalVelocity | Velocity to transform |
A 2-dimensional vector.
Name | Type | Read-only | Description |
---|---|---|---|
magnitude | float | R/O | Magnitude/length of the vector |
normalized | ksp::math::Vec2 | R/O | Normalized vector (i.e. scaled to length 1) |
sqr_magnitude | float | R/O | Squared magnitude of the vector |
x | float | R/W | x-coordinate |
y | float | R/W | y-coordinate |
vec2.angle_to ( other : ksp::math::Vec2 ) -> float
Calculate the angle in degree to other
vector.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::Vec2 | Other vector |
vec2.to_fixed ( decimals : int ) -> string
Convert the vector to string with fixed number of decimals
.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
decimals | int | Number of decimals |
vec2.to_string ( ) -> string
Convert the vector to string
A 3-dimensional vector.
Name | Type | Read-only | Description |
---|---|---|---|
magnitude | float | R/O | Magnitude/length of the vector |
normalized | ksp::math::Vec3 | R/O | Normalized vector (i.e. scaled to length 1) |
sqr_magnitude | float | R/O | Squared magnitude of the vector |
x | float | R/W | x-coordinate |
xzy | ksp::math::Vec3 | R/O | Swapped y- and z-coordinate |
y | float | R/W | y-coordinate |
z | float | R/W | z-coordinate |
vec3.angle_to ( other : ksp::math::Vec3 ) -> float
Calculate the angle in degree to other
vector.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::Vec3 | Other vector |
vec3.cross ( other : ksp::math::Vec3 ) -> ksp::math::Vec3
Calculate the cross/other product with other
vector.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::Vec3 | Other vector |
vec3.distance_to ( other : ksp::math::Vec3 ) -> float
Calculate the distance between this and other
vector.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::Vec3 | Other vector |
vec3.dot ( other : ksp::math::Vec3 ) -> float
Calculate the dot/inner product with other
vector.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::Vec3 | Other vector |
vec3.exclude_from ( other : ksp::math::Vec3 ) -> ksp::math::Vec3
Exclude this from other
vector.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::Vec3 | Other vector |
vec3.lerp_to ( other : ksp::math::Vec3,
t : float ) -> ksp::math::Vec3
Linear interpolate position between this and other
vector, where t = 0.0
is this and t = 1.0
is other
.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::Vec3 | Other vector | |
t | float | Relative position of mid-point (0.0 - 1.0) |
vec3.project_to ( other : ksp::math::Vec3 ) -> ksp::math::Vec3
Project this on other
vector.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
other | ksp::math::Vec3 | Other vector |
vec3.to_direction ( ) -> ksp::math::Direction
Point in direction of this vector.
vec3.to_fixed ( decimals : int ) -> string
Convert the vector to string with fixed number of decimals
.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
decimals | int | Number of decimals |
vec3.to_global ( frame : ksp::math::TransformFrame ) -> ksp::math::GlobalVector
Associate this vector with a coordinate system
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
vec3.to_position ( frame : ksp::math::TransformFrame ) -> ksp::math::GlobalPosition
Consider this vector as position in a coordinate system
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | Frame of reference |
vec3.to_string ( ) -> string
Convert vector to string.
pub sync fn angle_axis ( angle : float,
axis : ksp::math::Vec3 ) -> ksp::math::Direction
Create a Direction from a given axis with rotation angle in degree
Parameters
Name | Type | Optional | Description |
---|---|---|---|
angle | float | ||
axis | ksp::math::Vec3 |
pub sync fn angle_delta ( a : float,
b : float ) -> float
Calculate the difference between two angles in degree (-180 .. 180)
Parameters
Name | Type | Optional | Description |
---|---|---|---|
a | float | ||
b | float |
pub sync fn euler ( x : float,
y : float,
z : float ) -> ksp::math::Direction
Create a Direction from euler angles in degree
Parameters
Name | Type | Optional | Description |
---|---|---|---|
x | float | ||
y | float | ||
z | float |
pub sync fn from_vector_to_vector ( v1 : ksp::math::Vec3,
v2 : ksp::math::Vec3 ) -> ksp::math::Direction
Create a Direction to rotate from one vector to another
Parameters
Name | Type | Optional | Description |
---|---|---|---|
v1 | ksp::math::Vec3 | ||
v2 | ksp::math::Vec3 |
pub sync fn global_angle_axis ( angle : float,
axis : ksp::math::GlobalVector ) -> ksp::math::GlobalDirection
Create a Direction from a given axis with rotation angle in degree
Parameters
Name | Type | Optional | Description |
---|---|---|---|
angle | float | ||
axis | ksp::math::GlobalVector |
pub sync fn global_euler ( frame : ksp::math::TransformFrame,
x : float,
y : float,
z : float ) -> ksp::math::GlobalDirection
Create a Direction from euler angles in degree
Parameters
Name | Type | Optional | Description |
---|---|---|---|
frame | ksp::math::TransformFrame | ||
x | float | ||
y | float | ||
z | float |
pub sync fn global_from_vector_to_vector ( v1 : ksp::math::GlobalVector,
v2 : ksp::math::GlobalVector ) -> ksp::math::GlobalDirection
Create a Direction to rotate from one vector to another
Parameters
Name | Type | Optional | Description |
---|---|---|---|
v1 | ksp::math::GlobalVector | ||
v2 | ksp::math::GlobalVector |
pub sync fn global_look_dir_up ( lookDirection : ksp::math::GlobalVector,
upDirection : ksp::math::GlobalVector ) -> ksp::math::GlobalDirection
Create a Direction from a fore-vector and an up-vector
Parameters
Name | Type | Optional | Description |
---|---|---|---|
lookDirection | ksp::math::GlobalVector | ||
upDirection | ksp::math::GlobalVector |
pub sync fn look_dir_up ( lookDirection : ksp::math::Vec3,
upDirection : ksp::math::Vec3 ) -> ksp::math::Direction
Create a Direction from a fore-vector and an up-vector
Parameters
Name | Type | Optional | Description |
---|---|---|---|
lookDirection | ksp::math::Vec3 | ||
upDirection | ksp::math::Vec3 |
pub sync fn matrix2x2 ( a : float,
b : float,
c : float,
d : float ) -> ksp::math::Matrix2x2
Create a new 2-dimensional matrix
Parameters
Name | Type | Optional | Description |
---|---|---|---|
a | float | ||
b | float | ||
c | float | ||
d | float |
pub sync fn matrix4x4 ( ) -> ksp::math::Matrix4x4
Create a new 4-dimensional matrix
pub sync fn vec2 ( x : float,
y : float ) -> ksp::math::Vec2
Create a new 2-dimensional vector
Parameters
Name | Type | Optional | Description |
---|---|---|---|
x | float | ||
y | float |
pub sync fn vec3 ( x : float,
y : float,
z : float ) -> ksp::math::Vec3
Create a new 3-dimensional vector
Parameters
Name | Type | Optional | Description |
---|---|---|---|
x | float | ||
y | float | ||
z | float |