Find axis of rotation given rotation angle - math

I have a plane which is rotated 90 degrees around an unknown axis. I know a point and normal for the plane before and after the rotation. How can I find the axis of rotation?
I've done a sketch to illustrate - it's 2D but the problem is actually 3D.

I worked it out with some help from #davin.
Use the cross product to find the direction of the rotation axis. The two known points on the planes and the unknown point on the rotation axis make an isosceles triangle, so simple geometry finds the unknown point.

The axis of rotation is an eigenvector of the rotation matrix. Moreover, it has eigenvalue 1. Every rotation matrix has such an eigenvector. Then just apply the translation to the eigenvector (presuming you're rotating and then translating) to get the final axis of rotation.
Mathematically, you need to solve Rv = v, which is equivalent to finding the nullspace of R-I.

Related

Calculating Forward Vector Given Rotation in 3D

Given a Vector 3 of Euler Angles, how could one mathematically find the direction that object is facing.
In other words, how does Unity calculate the 'transform.forward' vector?
You should read up on spherical polar coordinates, noting the difference between conventional polar and Euler angles. But anyway the formula is (cos(pitch)cos(yaw), cos(pitch)sin(yaw), sin(pitch)). Note that the roll has no effect here.

finding the rotation axis

I'm using eigen library to rotate a plane to be parallel to the ground plane.
The ground plane is defined using the normal vector (0,0,1)
The target plane is a set of 3D points and a normal
The rotation angle is known
the normal vector of the plane as well as every point on that plane has to be rotated to be parallel to the ground plane
I'd like to use affine transformation from
http://eigen.tuxfamily.org/api/TutorialGeometry.html
something like this
Transform t = AngleAxisf(a,axis);
axis in this case is a matrix representing an arbitary axis, along which the rotation takes place.
How to find this axis?
Many thanks
Making two planes parallel can be done by making their normals parallel, so you just need to find the axis to rotate the target plane normal about. This is just the axis that is perpendicular to both your ground plane normal and your target plane normal which can be found using the cross product. In your case, if your target plane has a normal of [x,y,z], then the rotation axis is [y,-x,0].

3d rotation around the origin

I know there are plenty of questions about 3d rotation that have been answered here but all of them seem to deal with rotational matrices and quaternions in OpenGL (and I don't really care if I get gimbal lock). I need to get 3d coordinates EX:(x,y,z) of a point that always must be the same distance, I'll call it "d" for now, from the origin. The only information I have as input is the deltax and deltay of the mouse across the screen. So far here is what I have tried:
First:
thetaxz+=(omousex-mouseX)/( width );
thetaxy+=(omousey-mouseY)/( height);
(thetaxy is the angle in radians on the x,y axis and thetaxz on the x,z axis)
(I limit both angles so that if they are less than or equal to 0 they equal 2*PI)
Second:
pointX=cos(thetaxz)*d;
pointY=sin(thetaxy)*d;
(pointX is the point's x coordinate and pointY is the y)
Third:
if(thetaxz)<PI){
pointZ=sqrt(sq(d)-sq(eyeX/d)-sq(eyeY/d));
}else{
pointZ=-sqrt(abs(sq(d)-sq(eyeX/d)-sq(eyeY/d)));
}
(sq() is a function that squares and abs() is an absolute value function)
(pointZ should be the point's z coordinate and it is except at crossing between the positive z hemisphere and negative z hemisphere. As it approaches the edge the point gets stretched further than the distance that it is always supposed to be at in the x and y and seemingly randomly around 0.1-0.2 radians of thetaxz the z coordinate becomes NAN or undefined)
I have thought about this for awhile, and truthfully I'm having difficulty warping my head around the concept of quaternions and rotational matrices however if you can show me how to use them to generate actual coordinates I would be glad to learn. I would still prefer it if I could just use some trigonometry in a few axis. Thank you in advance for any help and if you need more information please just ask.
Hint/last minute idea: I think it may have something to do with the z position affecting the x and y positions back but I am not sure.
EDIT: I drew a diagram:
If you truly want any success in this, you're going to have to bite the bullet and learn about rotation matrices and / or quaternion rotations. There may be other ways to do what you want, but rotation matrices and quaternion rotations are used simply because they are widely understood and among the simplest means of expressing and applying rotations to vectors. Any other representation somebody can come up with will probably be a more complex reformulation of one or both of these. In fact it can be shown rotation is a linear transformation and so can be expressed as a matrix. Quaternion rotations are just a simplified means of rotating vectors in 3D, and therefore have equivalent matrix representations.
That said, it sounds like you're interested in grabbing an object in your scene with a mouse click and rotating in a natural sort of way. If that's the case, you should look at the ArcBall method (there are numerous examples you may want to look over). This still requires you know something of quaternions. You will also find that an at least minimal comprehension of the basic aspects of linear algebra will be helpful.
Update: Based on your diagram and the comments it contains, it looks like all you are really trying to do is to convert Spherical Coordinates to Cartesian Coordinates. As long as we agree on the the notation, that's easy. Let θ be the angle you're calling XY, that is, the angle between the X axis rotated about the Z axis; this is called the azimuth angle and will be in the range [0, 2π) radians or [0°, 360°). Let Φ be an angle between the XY plane and your vector; this is called the elevation angle and will be in the range [-π/2, +π/2] or [-90°, +90°] and it corresponds to the angle you're calling the XZ angle (rotation in the XZ plane about the Y axis). There are other conventions, so make sure you're consistent. Anyway, the conversion is simply:
x = d∙cos(Φ)∙cos(θ)
y = d∙cos(Φ)∙sin(θ)
z = d∙sin(Φ)

Axis Rotation Question

By using left hand rule, I rotate one object left and right using y axis, and rotate up/down using x axis.
After first object is rotated to the right, the up/down rotation should be using z axis.
However, when I try to rotate using z axis, after the first rotation, it has the same effect when I rotate using y axis.
Anyone has any ideas?
Thanks
The proper order of rotations in order to keep everything straight is roll, pitch, yaw. That is, rotation around the X axis, rotation around the Y axis, rotation around the Z axis.
Not sure what your question is, but if you're asking why this happens, the answer is that rotations are not commutative. That is, a rotation of theta about axis A followed by a rotation of phi around axis B is not the same as rotation of phi around axis B followed by a rotation of theta around axis A.
If you're asking why a sequence of operations that seems okay when you visualise it fails to work in code, be sure you're using a right-handed coordinate system. Also, it might be helpful to work through your various rotation matrices for the x, y and z axes using the unit vector (1,0,0) - in fact, if you do it on paper you'll get a better intuition for what's happening.
Thanks for all the answers:
Sorry I didn't state the problem clearly.
That's the typical gimbal lock problem.
and my solution is to use quaternion rotation

3d Parabolic Trajectory

I'm trying to figure out some calculations using arcs in 3d space but am a bit lost. Lets say that I want to animate an arc in 3d space to connect 2 x,y,z coordinates (both coordinates have a z value of 0, and are just points on a plane). I'm controlling the arc by sending it a starting x,y,z position, a rotation, a velocity, and a gravity value. If I know both the x,y,z coordinates that need to be connected, is there a way to calculate what the necessary rotation, velocity, and gravity values to connect it from the starting x,y,z coordinate to the ending one?
Thanks.
EDIT: Thanks tom10. To clarify, I'm making "arcs" by creating a parabola with particles. I'm trying to figure out how to ( by starting a parabola formed by a series particles with an beginning x,y,z,velocity,rotation,and gravity) determine where it will in end(the last x,y,z coordinates). So if it if these are the two coordinates that need to be connected:
x1=240;
y1=140;
z1=0;
x2=300;
y2=200;
z2=0;
how can the rotation, velocity, and gravity of this parabola be calculated using only these variables start the formation of the parabola:
x1=240;
y1=140;
z1=0;
rotation;
velocity;
gravity;
I am trying to keep the angle a constant value.
This link describes the ballistic trajectory to "hit a target at range x and altitude y when fired from (0,0) and with initial velocity v the required angle(s) of launch θ", which is what you want, right? To get your variables into the right form, set the rotation angle (in the x-y plane) so you're pointing in the right direction, that is atan(y/x), and from then on out, to match the usual terminology for 2D problem, rewrite your z to y, and the horizontal distance to the target (which is sqrt(xx + yy)) as x, and then you can directly use the formula in link.
Do the same as you'd do in 2D. You just have to convert your figures to an affine space by rotating the axis, so one of them becomes zero; then solve and undo the rotation.

Resources