my brain has caved, is this realy that hard? (moving angle)

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

my brain has caved, is this realy that hard? (moving angle)

Postby Gibbon » Fri Feb 25, 2011 11:06 am

Well, just wanted to say that i am completly at a loss for this.

nothing i seem to try works. I never thought it would be so hard to find the angle or direction a body is moving in?

what i dont understand are:
1.Everyone (other forums) tells me the "getbodyvelocity" gets me the direction the body is moving. If thats so, how come if i add torque to my body so that it now faces 45 degrees, and the body MOVES in that direction, the getbodyvelocty does not return 45, so.. what does it return? It returns a speed along the axis?

2.The idea of getting the direction by using the old coords against the new coords also brings me to the same issue? I end up with again, my object facing direction as say 45 and the direction vector of the old coords against the new coords is an extreamly small number?

All i want to know is the DIFFERENCE between the local facing angle to the local movement angle, so when i rotate the object againz it recalculates the difference again, and again and again, all the time.

If the object is facing 50 degrees but is moving at an angle say 30 degrees, how do i find that 30 degrees value??

Does anyone know how this can be done, it seem so easy but also seems to be.

direction.png
direction.png (12.28 KiB) Viewed 4160 times


Thanks
Andy
Gibbon
 
Posts: 44
Joined: Tue Dec 15, 2009 5:18 am

Re: my brain has caved, is this realy that hard? (moving ang

Postby JernejL » Fri Feb 25, 2011 4:01 pm

getbodyvelocty does not return rotational orientation, it returns body's current velocity in global space.

Body has velocity, position, omega (kinda like rotational velocity), each of these specifies its own property and it can be calculated in body-orientation or world-orientation.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: my brain has caved, is this realy that hard? (moving ang

Postby JoeJ » Fri Feb 25, 2011 5:36 pm

This looks like a simple trigonometry question (?)
You can get the green angle differnce by:

angDiff = acos (Normalize(facingUpVector).Dot (Normalize(movingVector))


and if you're in 2D, the 30deg angle asked in text is given by:

Normalize(movingVector)
globalAngle = atan2 (movingVector.x, movingVector.y)


Hope that helps
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: my brain has caved, is this realy that hard? (moving ang

Postby Gibbon » Sat Feb 26, 2011 7:46 pm

Hi, im sure it is a simple trig question? But why can i not do it?

The issues i dont understand that make this appear its NOT just a trig question is.

The facing vector i have, is a rotation number in degrees?? I am using a commend GetRotation, it return R value like 30 degrees or 60 degrees? Well... is that a vector? can i use this value in the equation u state??

The other thing is, this is in 3D but im only ever want to know the angle between one of the axis, just the as the picture shows.

So, just to help my understanding here:

moving vector is the GetBodyVelocity? and normalise that so that the length is always 1?

Facing vector??? like i said above, i get the facing value by "getting the rotation", is this correct?

One more thing i dont undertsand is this equation works out the angle from all axis??

I want, the angle between the local moving Z of the object and the local X rotation of object (the way the object is facing)

Please put me out of my misery...

Thanks
Andy
Gibbon
 
Posts: 44
Joined: Tue Dec 15, 2009 5:18 am

Re: my brain has caved, is this realy that hard? (moving ang

Postby Julio Jerez » Sat Feb 26, 2011 8:01 pm

you can get that by doin somethmk like this

vector vel (GetVelocity)

// project the velocity on teh floor
vel.y = 0;

Vcetor dir (GetForntVcetor of BodyMatrix)
dir.y = 0

normalize (dir)
normalize (vel)
float cosAngle (dir.DotProduct( vel))
float sinAngle (dir.CrosProduct(vel))
angle = atan2 (sinAngle, cosAngle);
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: my brain has caved, is this realy that hard? (moving ang

Postby Gibbon » Sat Feb 26, 2011 8:13 pm

HI, what do you mean by project the velocity to the floor??

And like i said, direction i have is in degrees??? Is that a vector?

Andy
Gibbon
 
Posts: 44
Joined: Tue Dec 15, 2009 5:18 am

Re: my brain has caved, is this realy that hard? (moving ang

Postby JoeJ » Sun Feb 27, 2011 4:28 am

What Julio means, is: if y is your up axis, you set it zero on both vectors, renormalize them so you can get the angle on the ground plane.
Think of it as if the sun comes straight from top, you take the angle of the shadow of the vertices.

But note something else: if you use BodyGetRotation, that returns 4(!) values (Orientation in Worldspace) in quaternion form.
If you use BodyGetMAtrix, that returns 16 values (Orientation and Location in Worldspace) in the following form:
xaxis.x, xaxis.y, xaxis.z, 0 (Julio names this one front)
yaxis.x, yaxis.y, yaxis.z, 0
zaxis.x, zaxis.y, zaxis.z, 0
origin.x, origin.y, origin.z, 1

So you can take one of the axis vectors to define your facing direction.
And the normalized velocity gives moving direction.
The projection removes 1 dimension, and a 2D unit vector contains sine and cosine to measure absolute angle.
Different: Dot product from 3D unit vectors gives cosine, to measure relative angle.

In general, using angles in 3D space is not good to handle or understand orientation + rotation (google Euler angles + glimbal lock).
The 3 orthogonal axis in the matrix are better. Add Code to visualize those axis to get it.
If you understand the dot product, it's easy to understand how transformation from one space to another and back works.
I tell you because i guess this is new to you? If so, you have to learn that very basics to proceed.
All this isn't newton specific.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: my brain has caved, is this realy that hard? (moving ang

Postby Gibbon » Mon Feb 28, 2011 5:30 am

Hi, yes i am new to matrix's, as upto now ive used leadwers stadard library to rotate objects, position objects, add forces, add velocity and return values for all of them as WORLD or LOCAL values.

So leadwerks allows you to do everything locally and globally, so i can quite grasp if this can be done using them above, or do i still need to do this using the matrix?

The one thing i cant get with matrices is the local and global coordinate system, is the coordinate system still a concern when using matrices?

I really am amazed at how difficult im finding it find the angle i want.

Its only so can calculate angle of attack for a wing.

You see the angle of attack is between relative flow and the wing chordline. Which is the angle between the moving body and the objects facing direction, which is what im trying to do.

But i get all confused because the above angle im trying to get could be when the aeroplane is vertical, on its side, upside down, so the angle needs to be local to the object all the time. (this is where i get all confused with the maths side)

Another way i look at it and find it hard to belive its not easily possible is:

Using leadwerks i can Getbodyrotation of z locally (the way i set as the front), so i can apply forces or movements and it will will always return me the direction of the body, if rotate it so its vertical, the angle will be 90. Its local.

I simply want the same but for direction the body is moving, its moving forward along its local z then then it would be 0, it its moving vertical it would be 90, but i still need it local, so if it rotates otherwise all values still remain correct.

Ive included 2 more examples of what im trying to achieve..

ex2.png
ex2.png (6.09 KiB) Viewed 4080 times

ex1.png
ex1.png (6.09 KiB) Viewed 4080 times


Direction i retive in degrees (unless there is another way)
Body direction, i dont? Liner velocity?
Angle not sure i dont know the above.

Thanks
Andy
Gibbon
 
Posts: 44
Joined: Tue Dec 15, 2009 5:18 am

Re: my brain has caved, is this realy that hard? (moving ang

Postby Julio Jerez » Mon Feb 28, 2011 9:09 am

the line I gave you do what you want, but I though you were doing for the floor.
for a general direction

all you nee to do is this

angle = acos (dotProduct (facing, moving))

facing and moving most be unit vectors.
the angle will be positive only you use the thirs axis of teh coodenate system to detemine on the sign, whi it waht I gave you first.
The method I gave you first asume the up vecotr is the thethso axis an dteh project is simple making y = 0.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: my brain has caved, is this realy that hard? (moving ang

Postby Gibbon » Mon Feb 28, 2011 9:18 am

Ok thanks julio.

Can you quickly explain, how do i get the the facing unit vector? (from the matrix?)
Is the rotation of Z the 3rd row of a matrix? is this the unit vector i use?

And also, could explain this more simply as im struggerling with it?
the angle will be positive only you use the thirs axis of teh coodenate system to detemine on the sign, whi it waht I gave you first.

Thanks
Andy
Gibbon
 
Posts: 44
Joined: Tue Dec 15, 2009 5:18 am

Re: my brain has caved, is this realy that hard? (moving ang

Postby Julio Jerez » Mon Feb 28, 2011 9:35 am

the facing unit vector will be the from vector of the matrix on the body.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: my brain has caved, is this realy that hard? (moving ang

Postby Gibbon » Mon Feb 28, 2011 10:21 am

Thanks Julio but i do not understand? The from vector of the matrix? What is the from vector?

Thanks
Andy
Gibbon
 
Posts: 44
Joined: Tue Dec 15, 2009 5:18 am

Re: my brain has caved, is this realy that hard? (moving ang

Postby JoeJ » Mon Feb 28, 2011 11:56 am

What math lib do you use? Newton or Leadwerks?
I don't have access to any code at the moment, but i can write some code from what i remember using Newton...


dMatrix planeGlobalMatrix;
NewtonBodyGetMatrix (planeBody, (float*)&planeGlobalMatrix);

dVector facingUnit = planeGlobalMatrix.m_front; // first vector, = x axis

dVector velocityUnit;
NewtonBodyGetVelocity (planeBody, (float*)&velocityUnit); // also given in global space
velocityUnit.Normalize(); // ignoring zero length check to keep it simple

float dot = velocityUnit % facingUnit; // i think newton uses % or / operator for dot, see dVector.h
float angleInRadians = acos(dot);


It's as simple as that.
Which one is the facing axis choosen from Matrix depends on your 3D-Model.
If dot gives trouble, it is this:

float dot = a.x * b.x + a.y * b.y + a.z * b.z;
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: my brain has caved, is this realy that hard? (moving ang

Postby Gibbon » Mon Feb 28, 2011 12:32 pm

Hi joe, i am using Leadwerks which has built newton game dynamics.

But i am very much looking forward to trying this!

I really do appriciate your efforts to help me.

I will rerport back as soon as ive give it a go.

Thanks
Andy
Gibbon
 
Posts: 44
Joined: Tue Dec 15, 2009 5:18 am

Re: my brain has caved, is this realy that hard? (moving ang

Postby Gibbon » Mon Feb 28, 2011 3:42 pm

Hi joe, well that does actually seem to be working great, and without realising i was so close with what i had on one of my attempts lol, all i needed to do was to get the facing direction from the matrix as apposed to euler angle.

But yes, thank you, much appriciated, been driving me crazy!

One thing now though, and i presume this is what julio mentioned, that the angle is always positive, even if the facing direction is lower than the moving direction. Is it easy enough to get the negative value?

thanks
Andy
Gibbon
 
Posts: 44
Joined: Tue Dec 15, 2009 5:18 am

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron