In 3 dimensional space i have an ine object between x and y axis.If the angle between x and y axis given,how can we find a vector value(i,j,k) ?please help to solve this problem.
Thanks in advance.
Depends on what X and Y axis are. Supposing this usual axis naming:
X and Y axis angle do not define the vector in 3D space (which I guess is what you want since you want a 3-component vector) because angle with X actually is the same than angle with Y (they're related).
You should explain what angles you have. This problem only has solution if the two angles are independent (or the space is 2D).
Related
I'm having trouble with a part of a school project of mine.
I need to find the vector v defined by the angles alpha and beta, but relative to a normal n instead of relative to the z axis.
I saw this question and answer, but it's only relative to the z axis, and I'm having trouble understanding how I can find v around a normal instead: 3D Vector defined by 2 angles
Thank you
You need two vectors, if you give me the normal vector and an angle between the point and that vector, that can be satisfied by a family of points that lie in a circle.
Then you need a second vector to determine which point is the correct one.
I have asked a question similar to this before but have since got further and also didn't tag the question right and wanted to get a bit of help on the maths around the question if possible.
I have a 3D sphere with points evenly spaced on its surface of which I know the coordinates. From these coordinates I am trying to define the orientation of some spikes that are coming out of the surface of my sphere along the vector between the centre of the sphere and the point at which the coordinates lie.
The idea is these euler angles will be very helpful in later aligning the spikes so they are all in roughly the same orientation if I am am to box out all of the spikes from an image.
Since the coordinates on the sphere are evenly spaced i can just take the average x, y and z coordinates to give me the centre and I can then draw a vector from the centre to each coordinate in turn.
The euler angles I need to calculate in this case are initially around the z axis, then around the new y axis, and finally again around the new z axis.
My centre point is currently being defined as the average coordinate of all my coordinates. This works as the coordinates are evenly spaced around the sphere.
I then use the equation that states
cos(theta) = dot product of the two vectors / magnitude of each vector multiplied together
on the x and y axis. One of my vectors is the x and y of the vector i am interested in whilst the other is the y axis (0,1). This tells me the rotation around the z axis with the y axis being 0. I also calculate the gradient of the line on this 2D plane to calculate whether I am working between 0 and +180 or 0 and -180.
I then rotate the x axis about the angle just calculated to give me x' using a simple 2D rotation matrix.
I then calculate the angle in the same way above but this time around the y axis using x' and z' as my second vector (where z' = z).
Finally I repeat the same as stated above to calculate the new z'' and x'' and do my final calculation.
This gives me three angles but when I display in matlab using the quiver3 command I do not get the correct orientations using this method. I believe I just do not understand how to calculate euler angles correctly and am messing something up along the way.
I was hoping someone more knowledgeable than me could take a glance over my planned method of euler angle calculation and spot any flaws.
Thanks.
I have two 3D vectors called A and B that both only have a 3D position. I know how to find the angle along the unit circle ranging from 0-360 degrees with the atan2 function by doing:
EDIT: (my atan2 function made no sense, now it should find the "y-angle" between 2 vectors):
toDegrees(atan2(A.x-B.x,A.z-B.z))+180
But that gives me the Y angle between the 2 vectors.
I need to find the X angle between them. It has to do with using the x, y and z position values. Not the x and z only, because that gives the Y angle between the two vectors.
I need the X angle, I know it sounds vague but I don't know how to explain. Maybe for example you have a camera in 3D space, if you look up or down than you rotate the x-axis. But now I need to get the "up/down" angle between the 2 vectors. If I rotate that 3D camera along the y-axis, the x-axis doens't change. So with the 2 vectors, no matter what the "y-angle" is between them, the x-angle between the 2 vectors wil stay the same if y-angle changes because it's the "up/down" angle, like in the camara.
Please help? I just need a line of math/pseudocode, or explanation. :)
atan2(crossproduct.length,scalarproduct)
The reason for using atan2 instead of arccos or arcsin is accuracy. arccos behaves very badly close to 0 degrees. Small computation errors in argument will lead to disproportionally big errors in result. arcsin has same problem close to 90 degrees.
Computing the altitude angle
OK, it might be I finally understood your comment below about the result being independent of the y angle, and about how it relates to the two vectors. It seems you are not really interested in two vectors and the angle between these two, but instead you're interested in the difference vector and the angle that one forms against the horizontal plane. In a horizontal coordinate system (often used in astronomy), that angle would be called “altitude” or “elevation”, as opposed to the “azimuth” you compute with the formula in your (edited) question. “altitude” closely relates to the “tilt” of your camera, whereas “azimuth” relates to “panning”.
We still have a 2D problem. One coordinate of the 2D vector is the y coordinate of the difference vector. The other coordinate is the length of the vector after projecting it on the horizontal plane, i.e. sqrt(x*x + z*z). The final solution would be
x = A.x - B.x
y = A.y - B.y
z = A.z - B.z
alt = toDegrees(atan2(y, sqrt(x*x + z*z)))
az = toDegrees(atan2(-x, -z))
The order (A - B as opposed to B - A) was chosen such that “A above B” yields a positive y and therefore a positive altitude, in accordance with your comment below. The minus signs in the azimuth computation above should replace the + 180 in the code from your question, except that the range now is [-180, 180] instead of your [0, 360]. Just to give you an alternative, choose whichever you prefer. In effect you compute the azimuth of B - A either way. The fact that you use a different order for these two angles might be somewhat confusing, so think about whether this really is what you want, or whether you want to reverse the sign of the altitude or change the azimuth by 180°.
Orthogonal projection
For reference, I'll include my original answer below, for those who are actually looking for the angle of rotation around some fixed x axis, the way the original question suggested.
If this x angle you mention in your question is indeed the angle of rotation around the x axis, as the camera example suggests, then you might want to think about it this way: set the x coordinate to zero, and you will end up with 2D vectors in the y-z plane. You can think of this as an orthogonal projection onto said plain. Now you are back to a 2D problem and can tackle it there.
Personally I'd simply call atan2 twice, once for each vector, and subtract the resulting angles:
toDegrees(atan2(A.z, A.y) - atan2(B.z, B.y))
The x=0 is implicit in the above formula simply because I only operate on y and z.
I haven't fully understood the logic behind your single atan2 call yet, but the fact that I have to think about it this long indicates that I wouldn't want to maintain it, at least not without a good explanatory comment.
I hope I understood your question correctly, and this is the thing you're looking for.
Just like 2D Vectors , you calculate their angle by solving cos of their Dot Product
You don't need atan, you always go for the dot product since its a fundamental operation of vectors and then use acos to get the angle.
double angleInDegrees = acos ( cos(theta) ) * 180.0 / PI;
Which matrix should i use?
http://en.wikipedia.org/wiki/Rotation_matrix
http://www.songho.ca/opengl/gl_anglestoaxes.html
There are derived matrices at bottom Axis Rotations , what are the usage of those matrices.
I can't understand the difference of those those, when to use what?
Why are derived matrices calculated?
Or when to use this?
and when to use this?
In 2D, you are using the X and Y axis. To do a rotation in 2D, you'll want to rotate on the Z axis, so that your points move on the X and Y axis. Use the Z-axis rotation matrix.
The X, Y, and Z axis rotation matrices are merely the simplified form of the other equation that has many more trigonometric functions involved. If you look at that one and plug in 0 for any of the two variables, you'll see it simplifies into one of the three axis specific versions.
Edit: Use the one with the Z in it. The third of the simpler versions.
I would like to know 2 things about the struct Vector2 in XNA:
Why does this struct only have X and Y instead of X,Y (origin) and X',Y' (destination)?
How can I calculate the direction of a vector with only the X,Y?
Thanks a lot in advance.
Kind Regards.
Josema.
The origin is usually assumed to be (0,0).
The X and Y are not actually the coordinates of a point.
They are X-axis and Y-axis components of the vector. A vector by definition has no origin, it represents only direction and length, not position.
Mathematically a vector has orientation (direction) and magnitude (length). It does not have position. When vectors are used in graphics programming to represent positions they are implicitly representing a point as an offset from the origin.
If you want to convert from a vector to an angle you can use simple trigonometry - the x and y components form two sides of a triangle and you can calculate the angle the vector makes with any axis. If you want to find the angle between two arbitrary vectors a and b it's acos(dot(a, b) / (length(a) * length(b)).
To calculate the direction (angle) of a vector most languages have an atan2(y,x) function.
1) A vector does not need length.
2) The numbers themselves determine the direction of the vector. Think of the cartesian plane. If you have a negative x and a positive y, then you are going top left...positive x, positive y, top right...etc. etc.