Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / That simple trigonometry

Author
Message
Koan
14
Years of Service
User Offline
Joined: 9th Nov 2009
Location:
Posted: 10th Nov 2009 01:10
Hello,
trying to understand trig for days, i want to know how to move on XZ plane (car turning left/right, or walking example), using sine and cosine, dont want to use newXValue. By the trigonometry circle in 2D, easy stuff from high scool, only XY plane:
x = cos (angle) * distance
y = sin (angle) * distance

Now, in case of walking around (on XZ plane) rotating around Y axes, i have to calculate new xz positions, based on current position, and distance as speed. This is it:
x = sin (angle) * r + x
z = cos (angle) * r + z

The question is: I want to know how this x = cos(angle) in (XY plane) has become x = sin(angle) in (XZ plane) ?

Im very confused, cuz to me sine represents vertical value, and cosine horizontal. To me it would be logical this way: x = cos (angle) and z = sin (angle).

This is how i see it, rotating around y axis, on XZ plane movement, sine is value that goes from 0 to "Z depth".

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 10th Nov 2009 13:12
Because what they teach you in school is that the angle is 0 when the vector is along the X axis, so that would imply moving sideways. The way to deal with that is either to subtract 90 from the angle all the time, but of course, that's just the same as using the other function.

"everyone forgets a semi-colon sometimes." - Phaelax
Koan
14
Years of Service
User Offline
Joined: 9th Nov 2009
Location:
Posted: 10th Nov 2009 18:15
Ive changed x to be cosine, z to be sine, as i wanted in first place:

x += dbCos(ay - 90) * turnSpeed; z += dbSin(ay + 90) * turnSpeed;

Angle - 90 is other function, excelent, a tiny step forward to understand, but still confused.

What do you mean by angle is 0 along X axis, and moving sideways?

I see that image i inserted didnt appear heres link:
http://img42.imageshack.us/i/triggraf.jpg/
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 10th Nov 2009 21:46 Edited at: 10th Nov 2009 22:00
Quote: "The question is: I want to know how this x = cos(angle) in (XY plane) has become x = sin(angle) in (XZ plane) ?"


It's because "angle zero" is when you are looking "North" or "into the monitor" along the Z axis. When rotating around the Y axis, the positive rotation is clockwise (right) from that angle. Have a look at the attached picture, that may make it clearer.

In 2D maths, the drawing would be different, you are probably accustomed to a system when angle zero is horizontal along the X axis.

P.S. If you position your character and camera to look along the Z axis at the start of the game, then this system is convenient, because "angle zero" will be the starting direction of the character.

Attachments

Login to view attachments
Koan
14
Years of Service
User Offline
Joined: 9th Nov 2009
Location:
Posted: 12th Nov 2009 18:51
Thank you much, i was missing that, the default view "North" and 0 degree, finally i understand movement, there are just few rules.

Cos - 90 equals sine. On y rotation going in z depth the angle is 0*, turning right angle increments, turning left angle decrements.

So on:
XY plane 0 z angle is by x axis. Not clockwise rotation.
ZX plane 0 y angle is by z axis. Clockwise rotation.
YZ plane 0 x angle is by y axis. Clockwise rotation ??
Koan
14
Years of Service
User Offline
Joined: 9th Nov 2009
Location:
Posted: 12th Nov 2009 19:57
Besides that, i tried to rotate around point using this logic, all i know is that you can mix y angle with z angle. What affect the value to that 2 angles isnt that important, lets say up down left right keys.
This is what i know:

x = dbCos(az) * d * dbSin(ay);

Ok, to move in x or -x direction you need cos of z angle, like in "standard" 2D xy plane, and if you move in z direction sure it wil affect the x. Like i first post the problem. No problem here.

y = dbSin(az) * d;

Elevation up down, like in XY plane sine is taken from z angle, standard stuff. No problem here.

z = dbCos(az) * d * dbCos(ay);

Z depth value is XZ movement where cosine of y angle gives Z++ and Z--,
Problem here: how come that cosine of az has a role in z movement?

And with all that the there is a glitch with the 90* degrees. What am i not seeing here. Here is the complete code, please check it out:

Login to post a reply

Server time is: 2024-10-01 16:30:34
Your offset time is: 2024-10-01 16:30:34