Date: 2024/08/17 20:32:01 UTC-07:00
Type: Denizen Script
path_position_by_time:
type: procedure
definitions: PointA[LocationTag - Start of straight line path.]|PointB[LocationTag - End of straight line path.]|Time[ElementTag - How long, in seconds, it takes to go from Point A to Point B.]|Pos[ElementTag - When, in seconds, in the straight line, the location is.]
description: Assuming a linear, uniform and straight line, with zero acceleration and constant speed, returns a LocationTag of where a point would be had it passed the given time travelling in the given line.
debug: false
script:
- define vector <[PointB].sub[<[PointA]>]>
- define length <[vector].vector_length>
# Cross multiplication
# If it takes Time to reach Length, then it takes x to reach Pos.
- define PosTime <[Time].mul[<[Pos]>].div[<[Length]>]>
# How many % of Time is PosTime?
# Proportion
- define x <[PosTime].div[<[Time]>]>
# Apply proportion as vector length. A vector half the original will end at the middle of the original. A 1/3 vector will end at 1/3 of the path.
- define PosVector <[vector].mul[<[x]>]>
# Adds the vector to the Point A.
- determine <[PointA].add[<[vector]>]>