0
votes

How to calculate 3D vector position after some time of movement at given angle and speed?

I have these variables available: current position, horizontal angle, vertical angle and speed.

I want to calculate position in the future.

Speed is defined as:

    float distMade = this->Position().GetDistanceTo(lastPosition);
    float speed = (distMade / timeFromLastCheck) * 1000; // result per sec 
    // checking every 100ms

Vertical angle coordinate system:
Facing 100% down -PI/2 (-1.57)
Facing 100% up PI/2 (1.57)

Horizontal angle:
Radian system, facing north = PI/2
Facing west = PI

Position 3d vector: x, y, z where z is height level.

3
specify what type of speed you have 1. angular speed angle''=omega'=epsilon or 2. cartesian speed position''=speed'=acceleration also specify coordinate system you use (H,V angles implies azimutal coordinate system but there are many more out there) - Spektre

3 Answers

0
votes

If your horizontal angle is azimuthal angle, and vertical angle is elevation, enter image description here

then

X = X0 + V * t *  Cos(Azimuth) * Cos(Elevation)
Y = Y0 + V * t * Sin(Azimuth) * Cos(Elevation)
Z = Z0 + V * t * Sin(Elevation)
0
votes

in that case your speed is cartesian speed

so:

  1. get point positions in cartesian space in different time

    • P0=(x0,y0,z0); - last position [units]
    • P1=(x1,y1,z1); - actual position [units]
    • dt=0.1; - time difference between obtaining P0,P1
  2. compute new position in time pasted from obtaining P1

    • P(t)=P1+(P1-P0)*t/dt
    • expand:
    • x=x1+(x1-x0)*t/dt
    • y=y1+(y1-y0)*t/dt
    • z=z1+(z1-z0)*t/dt
  3. if you need angh,angv,dist (and origin of your coordinate system is (0,0,0)

    • then you use this or modify it to your coordinate system:
    • dist = |P|=sqrt(x*x+y*y+z*z)
    • angv=asin(z/dist)
    • angh=atan2(y,x)
    • this is for: Z axis = UP, Y axis = North, X axis = East
    • if origin is not (0,0,0) then just substract it from P before conversion
0
votes

It looks like you are trying to predict a future position based on current position and previous position, and know the duration between them.

In this case, it seems like you don't need the angular directions at all. Just keep your "speed" as a vector.

speed = (position() - lastPosition) / (time-last_time);
future_position = position()+(future_time-time)*speed;

If your vector objects don't have operators overloaded, look for some that do or perform the calculation on each x,y,z component independently.

This is, of course, does not take into account any acceleration, just predicts based on current velocity. You could also smooth it out by averaging over the last 5-10 speeds to get a slightly less jittery prediction. If you want to account for acceleration, then you'll have to track last_speed in the same fashion you are tracking last_position currently, and acceleration is just speed-last_speed. And you'd likely want to do an average over that as well.