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

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

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

Postby JoeJ » Mon Feb 28, 2011 6:03 pm

If you have two vectors, their angle will be always <= 180deg, and it will be always positive.
If you have a clock, where it's 5 minutues to 12, angle is 5 minutes.
If it's 5 min after 12, angle is also 5 minutes.

Now, you want 5 to 12 to become -5 mins?
So question is: Is minute pointer left or right from hour pointer?
If the clock is on the x-z plane, y of all vectors are equal, the whole system is projectet allready on the xz plane.
It's 2-dimensional and you can feed the atan2 function with x and z values of the unit vectors,
as they represent sine and cosine. 11 o clock gives -5, 12 o clock gives 0, and 1 o clock gives 5.
So the difference between those angles contains a sign too.

But what do you do if the clock is not aligned to any easy plane?
This gets much more interresting and usefull...
Let's call the 12 o clock vec Xaxis.
You take the cross product between this and the 11 o clock vector.
This gives a vector that is perpendicular to both of them, so it points straight outwards the clock.
Let's normalize this new vector and call it the Yaxis.
Do it again and cross Yaxis with Xaxis, this gives the Zaxis vector pointing to 3 o clock.
Now you can take dot product from 11 o clock vec and the Zaxis: This gives the sine:
If it is negative, then angle is negative, and vector is on the left side from 12 o clock Xaxis.

So you got the answer, but you got more than that:
You got a 3 dimensional orthogonal coordinate system with all 3 basis vectors,
together with the position of the clock center you get a nice transformation matrix.
This leads to the right question: In relation to which space do i want to know that angle, and around which axis is that angle?

Now you can take a random point from global space and do the following:
global -= clockCenter
local.x = Xaxis.Dot(global)
local.y = Yaxis.Dot(global)
local.z = Zaxis.Dot(global)
You have transformad the point from global to local clock space.
Now you can again take the angle about Yaxis using atan2 (local.x, local.z) - don't forget to zero y and normalize first.

You can also rotate all 3 basis vectors from one space to another and so on...
Imagine the Orientation in 3D space by looking at the 3 basis vectors to become handy with transformation matrices.
And imagine the Rotation in 3D Space as a single angle in combination with a single axis! 3 angles are not good.
This is where quaternions become handy, but that may be part of the next lesson, depending on: What the hell do you wan't to do with that damn angle ??? :D
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 6:47 pm

lol and i thought my head had already caved in! :shock:

im going to have to have a few reads of the above!

The angle is simply used for "angle of attack" for the wings of an aeroplane, lift is generated by the angle of attack. Higher the angle more lift (in simple theory for now). So hence i need the angle.

But what is happening now is even when the wings angle of attack is negative (visually) the calculated angle of attack is still generating lots of lift, i need to know when the angle is negtive, only to simply tell it to stop calculating it. i dont actually NEED the negative number, just need it to stop at 0 if the wings facing direction is below the moving direction of the body.

Get me?

Thanks for help, keep it coming! :D

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 » Tue Mar 01, 2011 2:07 pm

You could transform the volocity vector to the local coord. system of the aeroplane.
Then each vector component tells you how much velocity goes top, left, upwards and opposite sides.
Maybe you'll want the lift effect also to become zero, if velocity goes from left or right?

Because the most lift effect comes if velocity goes to a direction slightly turned up from the front (i saw an illustration),
You could rotate the plane coord. system around the left / right axis, so that front vector
is aligned with this "direction of most lift effect".

But the simplest thing would be:
Construct the "direction of most lift effect" in local aeroplane space, transform it to global space and take the angle to velocity,
something like:

liftDirectionGlobal = (aeroplaneMatrix.FrontVec + 0.2 * aeroplaneMatrix.UpVec).Normalized();
angle = acos(liftDirectionGlobal.Dot(velocityUnit);

angle sign is not important anymore - may be an approx., but i'd try that first.
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 » Wed Mar 02, 2011 4:44 am

Hi Joe, once again thank for the help, appriciated. And i wish i didnt have to keep asking but ive gotten myself a little but more confused.

I know its down to me not completely understanding some of the things, such as "transfering a vector from global to local coords", i know what it means, but i cant visualise the outcome nor how it can be a use or benfit, but im trying my best to read up about it and find tutorials for it.

In the mean time, your doing an excellent job at teaching me! :D

In your last post, are you refering to replacing the original equation we spoke about for getting the angle? Or is this aswell as, to find the angle as a negative and positive.

The thing with lift is, it is perpendicular to the oncoming airflow (regardless to which was the plane is facing or pointing) which is why i need the angle of attack as that tells me the difference between the facing direction and the moving direction, so i can apply the lift force.

BUT, the last equation of doing it, getting the facing vector and velocity vector and getting the acos of the dot product works fine, apart from all i need to know is when the planes facing direction is below the moving direction.

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 » Wed Mar 02, 2011 12:37 pm

aeroplane.jpg
aeroplane.jpg (65.72 KiB) Viewed 2882 times


Ok, some visualisation...
On solving such problems, i always visualize vectors, points and and spaces of interest in graphics engine, to analyze and proof, and to check if it works in all cases. That makes things easy.

The top of my painting is the wing from side and from top. The red vector is the "direction of most lift effect" (hopefully got right), and the red gradient represents the amount of lift force, generated in relation to velocity vector.
If this is right, you only want to know the angle to that "effect vector", no sign anymore, because if velocity would go downwards, it would be in white space.

Bottom painting is about space to other space transformation:
You can see that you can get the coordinates in any space, if you take the dot product with each basis axis (2D as 3D).
This seems to be useless on the left painting, but works also in the right rotated paintng,
if you know the basis vectors in the same space as the point.
And calling BodyGetMatrix gives you the basis vector in global space, also velocity is in global space.
So you can transform either the global velovity to local aeroplane space,
or transform the "effect vector" from local to global space to take angle.

The magic is in the Dot product.
I'm sure i'll understand this while solving your problem, as you have a nice usecase.
The trig stuff is unimportant, it's just an interpretation from results given from Dot product(s).

But now back to the problem, i've missed something last time:
Looking at the top painting, the red volume forms a cone, but it's wider than high, so let's solve in local aero space, to make life easier:

dMatrix aeroMatrix;
BodyGetMatrix (aeroMatrix);
localVelocity = aeroMatrix.Unrotate(globalVelocity); // Unrotate contains the dot stuff, replacing this with 3 dots is left as the exercise
localVelocity.z *= 0.25; // trick to make cone 4 times wider than high, assuming z = sideways
const dVector effect = (dVector (1, 0.3, 0)).Normalized(); // assuming x = front, y = up
float dot = localVelocity.Dot(effect);
float angle = acos(dot);

That should do it.
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 » Wed Mar 02, 2011 5:25 pm

bahh joe!! lol. I really appeciate the illustration but unfortunatly, i dont think its right. I kind of understand the equation,. but i dont think it gets me what i want.

Ive drawn another illustration to try explain (maybe your right and im not understanding it properly, but i think the "lift" has confused you a little"

And just because not everyone knows about flight dynamics, being involved in avation i dont expect you to of course, so ill explain quickly.

If you look at the image you will see lift is ALWAYS perpendicular to airflow. Airflow is the opposite direction to which the plane is moving. (like holding your hand out of a moving car window (not recommended!:P) the airflow goes over and around you hand.)

When a plane pitches up, for a short while it will continues along its old direction so there is now angle, between the direction of the plane, and the way the plane (or wings) are facing, this is AOA, lift is generated because of AOA, making the plane starting rising untill its now MOVING in the same direction its facing again, and AOA returns to 0. All im trying to do is find that AOA. lol.

Please stay with me, your doing a great job and i really appriciate it.

Andy
aoa-lift.png
aoa-lift.png (64.5 KiB) Viewed 2874 times


Thank you
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 » Wed Mar 02, 2011 7:39 pm

Aha, so what i've got wrong is: the red effect vector should point downwards, not upwards.

This gives 1 change:

const dVector effect = (dVector (1, -0.3, 0)).Normalized(); // assuming x = front, y = up

The rest should work, but i don't calculate the angle of attack directly, since i only want to know how much lift force to apply.
Also, with my approach, the question - what happens if velocity goes sideways - is handled in one go.
So, the final result of my code would be:

const float maxAngle = 0.6;
if (angle < maxAngle)
{
float liftForceMultiplier /= maxAngle;
dVector liftForce = (globalVelocity.Cross(aeroMatrix.sideAxis)).Normalized(); // note: this might be the opposite, if so, swap vectors
liftForce *= liftForceMultiplier * maxLiftForceConstant;
}






If you have any data which is related to angle of attack and you want to reproduce exactly, does it also cover the sideways case?
Ignoring that for now, you could do:

dVector localVelProjectedOnWingsPlane = (dVector (localVelocityUnit.x, 0, localVelocityUnit.z)).Normalized(); // assuming y = up
float aoa = acos(localVelProjectedOnWingsPlane.Dot(localVelocityUnit));
if (localVelocityUnit.y < 0) aoa = -aoa; // omg - we got that damn angle!

Ooops - how overcomplicated - this is the same:
aoa = asin(localVelocityUnit.y) - OR - aoa = acos(localVelocityUnit.y), try both - i'm unsure as always on 2 options

I guess if aoa <= 0, extraLift =0.
if aoa = 0.6, extraLift = maxLiftForceConstant.
And if aoa >= 1.2, extraLift = 0
This would be same result as with my effect vector method, but maybe you can model the reaction more precisely.
Problem: It misses the sideways or backwards cases, so extra work must be done...

Let's handle the sideways case somehow:
float sideFactor = 1.0 - fabs(localVelProjectedOnWingsPlane.y); // assuming y = side
extraLift *= sideFactor; // no extra lift if flying sideways

If plane flies backwards, there should be a very similar effect, so do nothing or reduce it with similar method.

Apply to force, which direction is calced as above:
liftForce *= extraLift;

This is more complex and has special cases (hopefully i haven't forgot one), also it might feel less predictable to the pilot.


All this handles just the extra lift, not the "some not alot" lift.


Looking at your painting again, slowly i get an impression of what you want to simulate.
I also understand the shifting and then aligning direction and velocity thing can be annoyable.
If you would have drawn it in plane space (plane always unrotated), i still could not imagine how and when movement changes.
But then it would be less confusing for you to understand and develop solution,
because only the velocity changes - any other input is constant.
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 » Wed Mar 02, 2011 8:21 pm

Hi Joe (if your name is joe? :) ) im now struggerling to accept that

aoa = asin(localVelocityUnit.y)

finds me my AoA, im not doubting it becasue ive implemented it and it appears to do so.. lol. Its so simple compared to the previous attempts!!

Im presuming that is correct and im not just seeing things here, that aoa = asin(localVelocityUnit.y) calculates my angle ive beeen trying to get? no matrix or normalizing or dot product-ing!

Thank you very very much, appriciated your help and not giving up! I feel like i could ask you a whole bunch of questions, but dont want to start caving your brain in too!

Although.... lol, my next part to this whole thing is some julio has given up repeating to me, that in order to control a object (such as a aeroplane) i need to caclualte the torque generated by the forces then apply a torque that is calculated by the cross product of the force and the center of the wing?... this loose me.

But if im not mistaken, i think this refers to just generally how to control an object as ive read somthing (but still dont understand it) in the FAQ here: http://newtondynamics.com/wiki/index.ph ... _engine%3F

Any thoughts on that, or are you retiring? :D

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 » Wed Mar 02, 2011 8:56 pm

Be warned of the typo on wiki:

AddGlobalForce (Force, Point)
{
R = Point - BodyMatrix.Position; // -, not /
Torque = CrossProduct (R, Force);
NewtonAddForce (Force)
NewtonAddTorque (Torque)
}

R is the lever to the center of mass of the body.
If you snip a pencil at its tip, the lever to the center causes it's rotation.
The axis of rotation is perpendicular to both the force and the lever, thus the cross.
If yo snip it at it's center, no lever - no rotation - So you might not need to care in aerodynamics.

I saw this code first time in baraffs paper about collission resolving.
Now i see it everywhere. But out of context i miss something on that.
If some energy causes rotation, the force causing linear mevement must be reduced - this is not handled in this nice function - why?
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 » Fri Mar 04, 2011 8:11 pm

Hi joe, you still with me? :)

About the previous question, im still unsure about and leaving that aside for now.

The problem i have now is, once i calculate my lift force, i am adding them locally to the body, which isnt right. For example, lift is perpendicular to relative wind/wings moving motion, but if i add lift like i am doing (local to body) this is on the bodys facing direction and not the moving direction.

How do i add forces to an object in a direction other than just XYZ, but whilst also keep it local too?

Do you understand?

once i have solved these few bits i shall make a video showing my progress :D

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 » Sat Mar 05, 2011 5:32 am

Hi again, there was a line in above post that contained that already:

dVector liftForce = (globalVelocity.Cross(aeroMatrix.sideAxis)).Normalized(); // note: this might be the opposite, if so, swap vectors

This creates a global direction which is perpendicular to the wings and the velocity, it should be what you need (?).



On the torque again:
If you've a single centered motor, and it's force goes through centor of mass, no torque.
If you have 2 motors at same speed, and summed force from averaged center goes also through com, no torque.
But if 1 motor is turned off or slowed down, then you will need to handle torque.

Pencil example:
If i snip the pencil at it's tip, it will rotate but there's nearly none translational motion.
This means to me that if torque is generated, force to apply on com gets smaller.
How to calculate this? I could figure out myself, but there's another question:
If we would do this reduction, and use that on other example: Snip pencil on both tip and end at the same time,
then the torques would sum up to zero, but the forces would also become nearly zero, which is wrong.

Would it be correct to sum up all forces and torques as usual with AddGlobalForce,
and afterwards calculate new forces by measuring all applied forces with the previous torque sum?

This really gives my headache, luckily i didn't need it so far.
Maybe it's stuff for a new topic - i can't help there.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest