Paste #125684: path position by time

Date: 2024/08/17 20:29:51 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16


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.
    - determine <[vector].mul[<[x]>]>