View Full Version : creating local axis, flipping problems
kjaft 01262006, 11:50 AM 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 yAxis. I now need to calculate the x and zAxis, therefore first I caclulate the crossproduct between the worldUpvector (the yaxis) and the supplied yAchsis, 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


Shaderhacker
01262006, 08: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 yAxis. I now need to calculate the x and zAxis, therefore first I caclulate the crossproduct between the worldUpvector (the yaxis) and the supplied yAchsis, 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 yAxis isnt' the same as your starting yaxis or you'll get a zero vector when taking the crossproduct. 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 offhand which components to swap (I believe the z with whatever axis you are trying to compute), but do a search on google.
M
kjaft
01272006, 09:29 AM
Also, be sure you check to make sure that the user supplied yAxis isnt' the same as your starting yaxis or you'll get a zero vector when taking the crossproduct
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 matrixrotation on the coordinatesystem? Or Quaternations? Man, sorry, I'm a little bit slow on the uptake just now...
Shaderhacker
01272006, 06: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 matrixrotation on the coordinatesystem? Or Quaternations? Man, sorry, I'm a little bit slow on the uptake just now...
Should be at most 2 rotations.
M
UrbanFuturistic
01282006, 10: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 anticlockwise.
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 
Shaderhacker
01292006, 06: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 anticlockwise.
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 
What are you talking about?
M
UrbanFuturistic
01292006, 12: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.
Shaderhacker
01292006, 06: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
01292006, 10:22 PM
So what's up with all the rotations?
Shaderhacker
01302006, 12: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
02012006, 06: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
02012006, 06: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.
vBulletin v3.0.5, Copyright ©20002014, Jelsoft Enterprises Ltd.