Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/components/AppMenuObjectDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
const {
distance, massRatio, sizeRatio, relativePosition, relativeVelocity,
escapeVelocity, gravBound, eccentricityVector, semiMajorAxis,
orbitalPeriod,
orbitalPeriod, directionalRelativePosition, directionalRelativeVelocity,
} = useObjectCompareStats(focusedObject, compareObject, objects)

const graphComponents = [
Expand All @@ -87,6 +87,8 @@
useTemplateRef("distance-ref"),
useTemplateRef("relative-position-ref"),
useTemplateRef("relative-velocity-ref"),
useTemplateRef("directional-relative-position-ref"),
useTemplateRef("directional-relative-velocity-ref"),
useTemplateRef("escape-velocity-ref"),
useTemplateRef("eccentricity-ref"),
useTemplateRef("semi-major-axis-ref"),
Expand Down Expand Up @@ -190,6 +192,15 @@
ref="relative-velocity-ref" :units="VELOCITY_UNITS"
show-length has-graph>Relative velocity</SideMenuObjectVectorStat>

<SideMenuObjectVectorStat :value="directionalRelativePosition"
ref="directional-relative-position-ref"
:units="LENGTH_UNITS" has-graph>
Direct. rel. pos.</SideMenuObjectVectorStat>
<SideMenuObjectVectorStat :value="directionalRelativeVelocity"
ref="directional-relative-velocity-ref"
:units="VELOCITY_UNITS" show-length has-graph>
Direct. rel. vel.</SideMenuObjectVectorStat>

<SideMenuObjectStat :value="escapeVelocity" ref="escape-velocity-ref"
:units="VELOCITY_UNITS" has-graph>
Rel. escape velocity</SideMenuObjectStat>
Expand Down
55 changes: 54 additions & 1 deletion src/composables/useObjectCompareStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import type { StyledGravityObject } from "@/util/sim/object";
import { computed, toValue, type ComputedRef } from "vue";
import Vector3 from "@/util/linalg/Vector3";
import { DISTANCE_SMOOTHING, GRAV_CONSTANT } from "@/util/sim/constants";
import { forceOnObject } from "@/util/sim/odeConvert";
import Matrix from "@/util/linalg/Matrix";
import Vector from "@/util/linalg/Vector";

/** Return value of the object compare stats composable */
export type ObjectCompareStatsReturn = {
Expand All @@ -17,6 +20,16 @@ export type ObjectCompareStatsReturn = {
relativePosition: ComputedRef<Vector3 | undefined>
/** Relative velocity to compare object */
relativeVelocity: ComputedRef<Vector3 | undefined>
/**
* Directional position relative to compare object (directions are given by
* velocity and acting force of compare object)
*/
directionalRelativePosition: ComputedRef<Vector3 | undefined>
/**
* Directional velocity relative to compare object (directions are given by
* velocity and acting force of compare object)
*/
directionalRelativeVelocity: ComputedRef<Vector3 | undefined>
/** Relative escape velocity between the two objects */
escapeVelocity: ComputedRef<number | undefined>
/**
Expand Down Expand Up @@ -82,6 +95,45 @@ StyledGravityObject[] | null | undefined>): ObjectCompareStatsReturn {
object.position.subtract(otherObject.position))
const relativeVelocity = definedComputed((object, otherObject) =>
object.velocity.subtract(otherObject.velocity))

const force = definedComputed((_, otherObject, allObjects) =>
forceOnObject(otherObject, allObjects))
const directionalBasis = definedComputed((_, otherObject) => {
if (!force.value)
return undefined
const velocity = new Vector(otherObject.velocity.x,
otherObject.velocity.y, otherObject.velocity.z)
const forceVector = new Vector(force.value.x, force.value.y,
force.value.z)
const onb = Vector.orthonormalBasis(velocity, forceVector,
new Vector(1, 0, 0), new Vector(0, 1, 0), new Vector(0, 0, 1))
if (onb.length != 3)
return undefined
return onb as [Vector, Vector, Vector]
})
const directionalMatrix = computed(() => {
const basis = directionalBasis.value
if (!basis)
return undefined
return new Matrix(...basis).transpose().inverse()
})
const directionalRelativePosition = computed(() => {
if (!relativePosition.value || !directionalMatrix.value)
return undefined
const v = directionalMatrix.value.multiply(new Vector(
relativePosition.value.x, relativePosition.value.y,
relativePosition.value.z))
return new Vector3(v.get(0), v.get(1), v.get(2))
})
const directionalRelativeVelocity = computed(() => {
if (!relativeVelocity.value || !directionalMatrix.value)
return undefined
const v = directionalMatrix.value.multiply(new Vector(
relativeVelocity.value.x, relativeVelocity.value.y,
relativeVelocity.value.z))
return new Vector3(v.get(0), v.get(1), v.get(2))
})

const distance = definedComputed((object, otherObject) =>
object.position.subtract(otherObject.position).length())
const massRatio = definedComputed((object, otherObject) =>
Expand Down Expand Up @@ -142,7 +194,8 @@ StyledGravityObject[] | null | undefined>): ObjectCompareStatsReturn {
return {
relativePosition, relativeVelocity, distance, massRatio, sizeRatio,
escapeVelocity, gravBound, barycenter, eccentricityVector,
semiMajorAxis, orbitalPeriod,
semiMajorAxis, orbitalPeriod, directionalRelativePosition,
directionalRelativeVelocity,
}

}