Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2006-09-10 00:44:05

safra
Member
Registered: 2005-12-03
Posts: 41

Vector to angles

Hi,

I have another directx question. I have a normal vector (position on landscape). Now I want to align another mesh with the landscape using this normal vector. Does anyone know how I can get the rotation values in degrees (0..360) for all three axis based on the landscapes normal vector?

I used matrices before for this, unfortunatly this time I need another approach because matrices are not supported for this kind of mesh. I tried a lot with asin and acos but nothing worked. The only thing that seemed right was using:

xrot = ASin(LandVector.x);

But I couldn't get this working for the z-axis? I belief the Y -axis should just be 0 or the value I want it to point at, correct?

Any help would be much appreciated!

Offline

#2 2006-09-10 20:55:49

safra
Member
Registered: 2005-12-03
Posts: 41

Re: Vector to angles

Urgh, is this complicated? Basically I just have a normalvector where the x,y,z, values needs to be transformed to degrees (I think).

Offline

#3 2006-09-11 03:39:18

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

Re: Vector to angles

what do you mean in angles though, because theres more than one way depending upon the order of rotations, and which axis of rotations you use.

for example, you could define it as 2 angles for rotation around the x axis, then the y axis in that order, or around the z axis and y axis in that order, or around the y axis then z axis. etc etc.


The Beginning Of All Things To End.
The End Of All Things To Come.

Offline

#4 2006-09-11 04:59:04

safra
Member
Registered: 2005-12-03
Posts: 41

Re: Vector to angles

Perhaps this is more complicated then I thought. The directx wrapper has a Mesh SetRotation function for all 3 axis. My Thoughts were, a normal vector points in a certain direction depending on the x,y and z values.  So it should be possible to calculate the angles this vector makes with the x,y and z axis. As this is a landscape/mesh positioning issue my thoughts were also that horizontal rotation of the mesh (y-axis) is not related to the normal vector but depends on the direction the mesh should point at.  So needed are the x and z rotation angles to align the mesh with the landscape at a specific position. Is this relevant information, or am I completely lost here? I don't know about the order of rotations, perhaps this is something I should experiment with when I have a basic idea of how to solve this issue?

Offline

#5 2006-09-11 05:15:17

Dross
Member
Registered: 2006-08-24
Posts: 325

Re: Vector to angles

Firstly, let me say that I have no idea how directx works, but I hope this will be helpful.

Secondly, I assume that by the landscape's "normal vector" you mean a vector that is at right angles to the landscape in question, as opposed to a "normal" in the sense of "not unusual" vector. I'm also assuming that we're working in three-dimensional space since you refer to a z-axis.

Anyways, if you have a vector that is normal to the landscape denoted by

and a vector that is normal to the mesh denoted by
, then the angle between them,
can be expressed by:

Where:

and

I hope this helps, let me know if there's anything that needs further explaination.


Bad speling makes me [sic]

Offline

#6 2006-09-11 05:55:53

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

Re: Vector to angles

well first of all, just finding the angle isnt enough, because first of all, the mesh doesnt have a normal tongue. but even if it did, youd need a vector rotate around, but he said the mesh cant be rotated just using a matrix (at which you could find the cross product to rotate around)

one way you could do it with the landscape normal, is to extrapolate a set of axis to go with it, but again, that requires a matrix to rotate by, since you can only define xrot, yrot, zrot, i still need to know in which order directX does its rotations for these meshes, does it rotate around the x axis, then the y axis? or what?


The Beginning Of All Things To End.
The End Of All Things To Come.

Offline

#7 2006-09-11 06:05:18

Dross
Member
Registered: 2006-08-24
Posts: 325

Re: Vector to angles

Ah, I see - so you have to rotate around the x, y and z-axes in some order? Again, I'm not familiar with directx, I infered from the first post that it was simply the angle that was sought after.

Do you have (or can you get) the unit vector in terms of i, j and k with respect to the mesh you want to put it on? In this case you can use the formula above with

to find the angle between your normal vector and the x-axis of the mesh, and then do similar with j and k to find the appropriate angles there as well.

Is this any nearer to what you're after?


Bad speling makes me [sic]

Offline

#8 2006-09-11 10:11:48

safra
Member
Registered: 2005-12-03
Posts: 41

Re: Vector to angles

@ Dross, Yes, That's what I mean with normal vector and yes it is 3D where Y is up, x is right and Z is forward.

@ luca-deltodesco, I did a quick search for the rotation order but no luck so far. I will search further and post here if I find it. Is the solution different for each type of order or is there a basic approach and can I find out the correct order by trial and error?

Offline

#9 2006-09-11 18:04:16

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

Re: Vector to angles

safra wrote:

@ Dross, Yes, That's what I mean with normal vector and yes it is 3D where Y is up, x is right and Z is forward.

@ luca-deltodesco, I did a quick search for the rotation order but no luck so far. I will search further and post here if I find it. Is the solution different for each type of order or is there a basic approach and can I find out the correct order by trial and error?

the order of rotations does matter, simply because matrix multiplication is not always commutive, i.e. AB doesnt always equal BA

you can figure out the order by just rotating the mesh around changing one value at a time and seeing how it effects its orientation.


The Beginning Of All Things To End.
The End Of All Things To Come.

Offline

#10 2006-09-11 22:21:08

safra
Member
Registered: 2005-12-03
Posts: 41

Re: Vector to angles

I did a test with 2 meshes. mesh1 by default rotated on all 3 axis in one call. Mesh 2 rotated by each axis individually at a time. The order does not influence the end rotation. Mesh 2 always ends up exactly like Mesh 1.

Offline

#11 2006-09-12 03:11:34

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

Re: Vector to angles

no, the order DOES influence the end rotation, but it still depends on how directx handles things, sice its not influencing end result, it simply means, that whenever you change a rotational value, it reacalculates the rotation using the same order of rotations from the base. rather than rotating the current rotation matrix.


The Beginning Of All Things To End.
The End Of All Things To Come.

Offline

#12 2006-09-12 03:23:07

safra
Member
Registered: 2005-12-03
Posts: 41

Re: Vector to angles

luca-deltodesco, I belief you for the full 100%. It was just to say that I cannot get the rotation order by doing what you suggested as no matter what order I tried it resulted in the same end position. I hope I can find more about this.

Offline

#13 2006-09-12 08:11:26

safra
Member
Registered: 2005-12-03
Posts: 41

Re: Vector to angles

There is is still no 100% clear answer to this but all of us, including real DirectX experts online, think it is YXZ (Y > up, X > right, Z > forward) because all functions related to this have YawPitchRoll in it which basically stands for YXZ (not sure if this is the same in maths terminology?).

Last edited by safra (2006-09-12 08:12:46)

Offline

Board footer

Powered by FluxBB