0

I use the following code (from stackoverflow) to rotate point around another point. It work great for the yaw rotation axis.

How do I modifiy this code for a pitch axis rotation?

double x1 = point.x - center.x;
double y1 = point.y - center.y;

double x2 = x1 * Math.cos(angle) - y1 * Math.sin(angle));
double y2 = x1 * Math.sin(angle) + y1 * Math.cos(angle));

point.x = x2 + center.x;
point.y = y2 + center.y;
Leon
  • 554
  • 4
  • 18
  • change all `y` to `z` – Spektre Jun 08 '20 at 06:52
  • It doesn't work, it rotates in Roll axis. Thx anyway. – Leon Jun 08 '20 at 07:20
  • then change `x` to `z` instead... the axis of rotation should not be changing in the rotation formula so if `z` is missing you rotating around `z` (usually roll)... if `x` (usually pitch) and if `y` (usually yaw) ... your notation is different so you have to try which combination is doing what you need. Also with more complex transformations you would be better of using [4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) – Spektre Jun 08 '20 at 07:26
  • Same result: roll axis. I may have a mistake somewhere. For information, I already use matrix transformation, but for single axis rotation, I try to avoid unnecessary multiplication. – Leon Jun 08 '20 at 08:00
  • render the matrix as in the link ... its possible you got corrupted axises ... – Spektre Jun 08 '20 at 08:03

0 Answers0