3d rotation around the source

I know there are many 3D rotation questions that have been answered, but they all seem to be dealing with rotational matrices and quaternions in OpenGL (and I don't care if I get a cardan lock). I need to get the 3d coordinates of EX: (x, y, z) of the point, which should always be the same distance, let's call it ā€œdā€ at the moment, from the origin. The only information I have as input is the deltax and mouse delta on the screen. So far I have tried:

At first:

thetaxz+=(omousex-mouseX)/( width ); thetaxy+=(omousey-mouseY)/( height); 

(thetaxy is the angle in radians along the x, y axis and taxz on the x, z axis) (I limit both angles so that if they are less than or equal to 0, they are equal to 2 * PI)

Secondly:

 pointX=cos(thetaxz)*d; pointY=sin(thetaxy)*d; 

(point X is the coordinate of point x, and point Y is 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 is quadratic, and abs () is a function of absolute value) (the point Z must be the coordinate of the point z, and it does not intersect between the positive hemisphere z and the negative z-hemisphere. As you approach the edge, the point stretches farther than the distance by which it should always be in x and y and, apparently, randomly around 0.1-0.2 radiant, the z coordinate becomes NAN or undefined)

I thought about this for a while, and, frankly, I had difficulty deforming 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 happy to know. I would prefer it if I could just use some trigonometry on several axes. Thank you in advance for any help, and if you need more information, just ask.

Hint / last minute idea: I think this may have something to do with the z position, affecting the x and y positions, but I'm not sure.

EDIT: I drew a diagram: enter image description here

+7
source share
1 answer

If you really want to succeed in this, you will 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 among the simplest ways to express and apply rotations to vectors. Any other idea that may arise in someone is likely to be a more complex reformulation of one or both of them. In fact, it can be shown that rotation is a linear transformation and therefore can be expressed as matrix . Rotations of quaternions are simply a simplified means of rotating vectors in 3D and, therefore, have equivalent representations of matrices.

However, it seems that you are interested in capturing an object in your scene with a mouse click and rotating naturally. In this case, you should look at the method for numerous examples that you might want to review). It still requires you to know that you need to make quaternions. You will also find that at least a minimal understanding of the basic aspects of linear algebra will be helpful.

Update . Based on your chart and the comments it contains, it looks like all you are really trying to do is convert Spherical Coordinates to Cartesian Coordinates . As long as we agree with the designation, this is easy. Let & theta; the angle you call XY, that is, the angle between the X axis rotated around the Z axis; this is called the azimuthal angle and will be in the range [0, 2 [pi]) radian or [0 [deg.], 360 [deg.]]. Let & phi; be the 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 this corresponds to the angle that you call the angle XZ ( rotation in the XZ plane around the Y axis). There are other conventions, so make sure you are consistent. Anyway, the conversion is simple:

  x = d āˆ™ cos (Ļ†) āˆ™ cos (Īø)
 y = d āˆ™ cos (Ļ†) āˆ™ sin (Īø)
 z = d āˆ™ sin (Ļ†) 
+5
source

All Articles