View Full Version : creating local axis, flipping problems

 kjaft01 January 2006, 12:50 PMHey folks, got a stupid problem here. I need to calculate a local axis for object creation. The user supplies a vector which is to be the object's y-Axis. I now need to calculate the x- and z-Axis, therefore first I caclulate the cross-product between the world-Up-vector (the y-axis) and the supplied y-Achsis, then based on that the other axises. After wondering first it became obviout to me why flipping occurs: if the angle between vectors changes over a certain amount the nrmal direction reverses. So what could be a solution for calculating an object's coordinate system in a stable way? cheers felix
01 January 2006, 09:37 PM
Hey folks, got a stupid problem here. I need to calculate a local axis for object creation. The user supplies a vector which is to be the object's y-Axis. I now need to calculate the x- and z-Axis, therefore first I caclulate the cross-product between the world-Up-vector (the y-axis) and the supplied y-Achsis, then based on that the other axises. After wondering first it became obviout to me why flipping occurs: if the angle between vectors changes over a certain amount the nrmal direction reverses.
So what could be a solution for calculating an object's coordinate system in a stable way?

cheers
felix

Use the previously made coordinate system and rotate it with respect to the new coordinate system and replace your new coordinate system with that rotated coordinate system. You are essentially rotating based on a rate of change of the original coordinate system from the start. Also, be sure you check to make sure that the user supplied y-Axis isnt' the same as your starting y-axis or you'll get a zero vector when taking the cross-product. The best thing would be to write a function that would give you an arbitrary coordinate frame based on ONLY the user supplied axis. You can get this by swapping components and taking the negative. I forget off-hand which components to swap (I believe the z with whatever axis you are trying to compute), but do a search on google.

-M

kjaft
01 January 2006, 10:29 AM
Also, be sure you check to make sure that the user supplied y-Axis isnt' the same as your starting y-axis or you'll get a zero vector when taking the cross-product
Yeah, I took that into account but i was nat the problem.

Anyway thanks fo your tips, i'll give that a try. Would that probably be a matrix-rotation on the coordinate-system? Or Quaternations? Man, sorry, I'm a little bit slow on the uptake just now...

01 January 2006, 07:25 PM
Yeah, I took that into account but i was nat the problem.

Anyway thanks fo your tips, i'll give that a try. Would that probably be a matrix-rotation on the coordinate-system? Or Quaternations? Man, sorry, I'm a little bit slow on the uptake just now...

Should be at most 2 rotations.

-M

UrbanFuturistic
01 January 2006, 11:30 PM
That 'over a certain amount' should be equivelant to, say, the z to -z point when you're calculating normals for backface culling.

Now, assuming you know how to calculate a surface normal, if you want to reverse the normal you calculate in the opposite direction ie: instead of using the vectors v0->v1 and v1->v2 you go v2->v1 and v1->v0

So, at this point I'm assuming you're going GlobalY->Global0 Global0->AxisY to get the X axis then doing a cross product of the X and Y to get the Z. Now, if you want to be able to say where the X axis is going to appear you need to visualise the Global and Local Y axes as if they're on a flat plane, facing you, and the direction of the vectors is anti-clockwise.

Now, I'm not 100% certain about this but I think the crossover point will be when Z of the Y axis goes from positive to negative numbers? There are two ways to deal with this, either swop the direction of the vectors or swop their order in the cross product calculation so...

| i_ j_ k_ |
| a1 a2 a3 |
| b1 b2 b3 |

becomes

| i_ j_ k_ |
| b1 b2 b3 |
| a1 a2 a3 |

01 January 2006, 07:19 AM
That 'over a certain amount' should be equivelant to, say, the z to -z point when you're calculating normals for backface culling.

Now, assuming you know how to calculate a surface normal, if you want to reverse the normal you calculate in the opposite direction ie: instead of using the vectors v0->v1 and v1->v2 you go v2->v1 and v1->v0

So, at this point I'm assuming you're going GlobalY->Global0 Global0->AxisY to get the X axis then doing a cross product of the X and Y to get the Z. Now, if you want to be able to say where the X axis is going to appear you need to visualise the Global and Local Y axes as if they're on a flat plane, facing you, and the direction of the vectors is anti-clockwise.

Now, I'm not 100% certain about this but I think the crossover point will be when Z of the Y axis goes from positive to negative numbers? There are two ways to deal with this, either swop the direction of the vectors or swop their order in the cross product calculation so...

| i_ j_ k_ |
| a1 a2 a3 |
| b1 b2 b3 |

becomes

| i_ j_ k_ |
| b1 b2 b3 |
| a1 a2 a3 |

-M

UrbanFuturistic
01 January 2006, 01:55 PM
He's trying to define the X axis of a freely defined Y axis with (GlobalY x LocalY) which is the same equation as for calculating a Normal vector on a polygon (the cross product for the vectors defined by the first three points).

The reason the X axis is flipping at a certain point is the same as the reason why the Normal for a poly will flip if you reverse the vertex order for the vector calculations.

01 January 2006, 07:54 PM
He's trying to define the X axis of a freely defined Y axis with (GlobalY x LocalY) which is the same equation as for calculating a Normal vector on a polygon (the cross product for the vectors defined by the first three points).

Oh, well, that was already described though.

The reason the X axis is flipping at a certain point is the same as the reason why the Normal for a poly will flip if you reverse the vertex order for the vector calculations.

I think we know that too.

-M

UrbanFuturistic
01 January 2006, 11:22 PM
So what's up with all the rotations?

01 January 2006, 01:11 AM
So what's up with all the rotations?

What is your solution? If you were to build several points along a strand of hair where for every point there was a corresponding coordinate system and the hair twisted around and around, how would you build your coordinate system so that when the hair deforms, there's no flipping of the normals? This is the problem.

Building a randomly oriented coordinate system at each point (which is what he is doing) isn't the correct solution.

-M

kjaft
02 February 2006, 07:54 PM
thanks guys, I'm sure that'll help me in some way - unfortunately i'm busy on some other stuff again at the moment.

cheers
felix

CGTalk Moderation
02 February 2006, 07:54 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

1