3D Trigonometry

Azylaminaz

Vox Populi
Reaction score
91
I'm sure it isn't as complicated as it is in my head. I just get confused thinking about it I guess.

What I am looking for are the mathematical functions to get the new X, Y, Z position. Let me spell it out.
Take a point X, Y, Z, say 32.00, 32.00, and 64.00. Now I want to be able to make this point move in a straight line towards any given angle (so a growth of 60° up and in an X/Y degree of 45° (towards the top right). I want to move this point say 50 units.

How would I get the new X, Y, Z?

I'm pretty sure you would do the same thing with just X and Y, just twice.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
cos(angle) * distance = new x
sin(angle) * distance = new y

Did you want the Z to change? I'm mostly assuming that the Z was constant in this scenario
 
Reaction score
456
newX = x + distance * Cos(azimuth) * Sin(zenith)
newY = y + distance * Sin(azimuth) * Sin(zenith)
newZ = z + distance * Cos(zenith)
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
Uberplayer has it.

The derivation of this stuff is exciting though, and knowing how to get to stuff increases confidance in the thingy, so here goes;

Start out with this triangle:
trigx.png


The red z is the zenith, r is the distance of the movement, delta z is the change in the height of the object, and d is the combined x/y component of the vector (useful because it is the hypotenuse of the triangle formed by x and y components).

We start here on the x-y/z plane because we can actually do something with the known z and r values; in this image we really have two congruent triangles, with the second one formed out of r and the z axis. With this simple knowledge and basic 2-dimensional vector math we can conclude that the delta z side is congruent with the side of the other triangle formed by the z-axis line, and is thus visibly equal to r*cos(z). We can compare the other corresponding lines to conclude that d is equal to r*sin(z).

//==skip to next comment if you don't want awesome math==

You can alternatively find d based on delta z and r via a far more hawt method: PYTHAGOREAN IDENTITIES!

d^2 = r^2 - (delta z)^2
d = Sqrt(r^2 - r^2*cos^2(z))
d = Sqrt(r^2(1 - cos^2(z)))
Since we're using pythagorean identities already, we already know that 1 - cos^2 is equal to sin^2:
d = Sqrt(r^2sin^2(z))

d = r*sin(z)

Awesome!


//==time wasting over!!!==

Now, we have two useful things. One is the change in the Z value, which we found to be r*cos(z). The other was the length of d, which is r*sin(z). Which is also the hypotenuse of the triangle formed by the X and Y of the vector:

trig3.png


'a' is for 'azimuth,' or the horizontal angle. Basic 2d vector math. x = d*cos(azimuth), y = d*sin(azimuth)

Since d is r*sin(zenith), we can punch that in and basically get Uberplayer's formulas:

new Z = Z + r*cos(zenith)
new X = X + r*sin(zenith)*cos(azimuth)
new Y = Y + r*sin(zenith)*sin(azimuth)
 

roXplosive

New Member
Reaction score
15
The posters before got the math right . Idk if I can make it more clear but I think that the problem you had was another one . let me see if I get it straight : you have a point P(xp,yp,zp) and you want to move it a distance "d" towards the angles alpha (the horizontal rotation) and betha (vertical rotation) . This is the simplest thing consider the transformations done . Now take the plane containing the coordinates of point D (xd,yd,zd) and the right Oz ; we mark on this pland the line that makrs its intersection with xOy plane . Now the angle between this line and OD is the zenith . We draw a perpendicular line downwards and measure the values obtained :



In the resulting triangle , conform to the definition of Sin and Cos functions we get :

zd=d*sin(betha)

Let us name the segment in the xoy plane length with "l" :

l=d*cos(betha)

Now for the xOy plane :



we get :

xd=l*cos(alpha)=d*cos(betha)*cos(alpha)
yd=l*sin(aplha)=d*cos(betha)*cos(alpha)

Now this new positions are obtained from origin for simplicity but the origin of your new point is P(xp,yp,zp) and all we got to do is translate theese coordinates accordingly obtaining :

NewX=xp+d*cos(betha)*cos(alpha)
NewY=yp+d*cos(betha)*sin(alpha)
NewZ=zp+d*sin(betha)

As a note the equations I got are the same as the others if you take into account that zenith = PI/2-betha and sin(pi/2-u)=cos(u) and vice versa (the second fundamental trigonometric equality) .

If you want to rotate the point P(xp,yp,zp) around a point q(xq,yq,zq) with aplha degrees into horizontal plane and betha into the vertical , the rotations being upwards (for betha>0) and counterclockwise in the horizontal plane this is what you have to do :

1. Obtain L the length of PQ L=sqrt((xp-xq)^2+(yp-yq)^2+(zp-zq)^2)
2. Obtain the elevation betha0=arcsin((zp-zq)/L) . Note Arcsin returns alues in the interval [-pi/2,pi/2] and it's enough to draw a sphere using as elevation
3. Obtain the base rotation angle :
a) alpha0=arccos((xp-xq)/(L*cos(betha0))) This returns values into [0,pi] interval and is accurate when yp-yq>0
b) alpha0=pi+arccos((xp-xq)/(L*cos(betha0))) and this returns values from [pi,2*pi] when yp-yq<0

Now you got the radius the basic azimuth and zenith (pi/2-betha) and you got to add your rotations on top of theese and recalcutae for the point P the position based around point Q.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top