-1

I try to write a rotation system for a theoratical flight device. My main problem is that I practically nearly never rotate around the axes of the coordinate system, but around the axes of the vehicle (pitch, roll, jaw). An object rolled around it's own z axis changes a following pitch rotation around its x axis.

My furthest idea is to use a position vector and three direction vectors of the vehicle which describe the positions {1,0,0},{0,1,0},{0,0,1}. I guess this vectors could somehow be used to store the axes of the object. When rotating the vehicle I would rotate two of this points around the axis symbolised by the the remaining point. As vectors I use javafx.geometry.Point3D.

So far I have this code for my start rotation which don't respects the vehicles rotation which it gets over time. Further is rotates a JavaFX shape which is also not my goal. (I want to have and transform raw coordinates for other uses than just drawing them)

final Point3D isFacing = new Point3D(0, 0, 1).normalize();
final Point3D shouldFace = position.subtract(goalDirection).normalize();

final double rotationAngle = Math.toDegrees(Math.acos(isFacing.dotProduct(shouldFace)));

final Point3D rotationAxis = isFacing.crossProduct(shouldFace).normalize();

Rotate rotate = new Rotate(rotationAngle, rotationAxis);
model.getTransforms().addAll(rotate);

How to store the parameters? How to compute the rotations? flight vehicle rotation axes

Community
  • 1
  • 1
jackjuni
  • 69
  • 6
  • *How to store the parameters? How to compute the rotations?* -> I suggest you to write some code, helps almost every time – Lino May 09 '19 at 08:28
  • 2
    You will need bunch of s=Linear Algebra. Google for quaternions. – talex May 09 '19 at 08:31
  • @Lino I added the code I have so far. – jackjuni May 09 '19 at 08:51
  • @talex what do you mean with s=Linear algebra? – jackjuni May 09 '19 at 08:52
  • @talex do you have a good source to learn about quaternions? Because this is very high-level, and I'm not a mathematics student/professor. – jackjuni May 09 '19 at 08:54
  • It is typo. Should be just "Linear Algebra". As for quaternion question. You have to google youself, I'm not mathematician too. And it is not that difficult. Just bunch of matrix multiplication. – talex May 09 '19 at 08:58
  • @talex what is your opinion on my idea to give the object its own axes and rotate it with/around them? – jackjuni May 09 '19 at 09:04
  • I don't understand al details, but if I got it correctly it should work, but will require some math to do. – talex May 09 '19 at 09:11
  • @talex just for my information, what is the reason for this question to get down-voted? I explained my goal and the ideas I had so far, also it isn't off-topic. – jackjuni May 09 '19 at 09:15
  • @jackjuni have no idea. Maybe it little bit vague. – talex May 09 '19 at 09:16

1 Answers1

1

If this is the first time you've tried something like this, try doing something very basic and simple first.

Follow these steps:

  • Try defining a cuboid, a List of 8 3D points around an origin.
  • Write some code to vector-render it in 3D perspective, drawing the 12 lines between the edge points, where each point is (X/(Z + dist)*scale, Y/(Z+dist)*scale), where dist is some amount to push the object out in your view, and scale is a magnification factor.
  • Now try rotating in the roll axis: for each point, calculate X1 = X*cos(roll) + Y*sin(roll) and Y1 = Y*cos(roll) - X*sin(roll)
    • this will give you a new set of points - make sure you can draw these instead. Your cuboid should appear tilted.
    • what we've just done is open out a matrix multiplication by a rotation transformation matrix.
    • I'm assuming you are looking down the Z-axis positive, which means that rolling is rotation around Z, in the X-Y plane.
  • Now try another rotation around the pitch (X) axis, rotating in the Y-Z plane: Y2 = Y1*cos(pitch) + Z*sin(pitch) and Z1 = Z*cos(pitch) - Y1*sin(pitch)
    • and render that: the shape should be nodding at you.
  • And finally: another rotation around the yaw (Y) axis, rotating in the X-Z plane: X2 = X1*cos(yaw) + Z1*sin(yaw) and Z2 = Z1*cos(yaw) - X1*sin(yaw)

You can now point the object anywhere you like. You are explicitly applying the rotations in order: roll it, then pitch it, and then yaw/orientate it. Once you understand the steps of what you are doing you can try writing this out as 3x3 matrices - you'll see that you can premultiply a single matrix to perform the transform for arbitrary roll/pitch/yaw.

And as you've observed, applying those transforms in a different order will change the outcome, but the matrix multiplication isn't commutative: changing the order messes it up.

Once you've got those basics firmly in your head, go off and read about more of the principles and practice. A good goal is to be able to draw a shape and spin it, translate it around your viewpoint, slide it left/right up/down. There is a clever way of using a 4x4 matrix, which captures the translation vector directly, see How does 4x4 matrix work in 3d graphic?.

But get a sinple thing working first, where you understand every single part. Then more advanced approaches, quaternions mentioned above etc, won't seem so daunting.

SusanW
  • 1,550
  • 1
  • 12
  • 22
  • Thank you very much, but this still looks like I would still rotate around the coordinate origin, my objects axes are not just translated tho, but also rotated, so just moving the object to the origin to rotate it wouldn't be enough. the rotation around a fixed axis is not that difficult, but to find this axes is what makes me trouble. – jackjuni May 09 '19 at 09:13
  • @jackjuni Oh! yes, absolutely. Define the Object in its original model location at the origin, and rotate it there. Then translate it "out there" to its actual x,y,z location. Then correct for your viewpoint/camera position (adding `dist` in the example above). But, yes, apply the rotation to the model geometry at origin and then translate it to its real place. Does that make sense? – SusanW May 09 '19 at 09:19