0

When rotating a point around another point in 2D space, the rotated point is farther away from the rotation center than the original one.

I'm basically using Nil's answer from: Rotating a point about another point (2D)

public static Point2D.Double rotate_point(double cx, double cy, double angle, Point2D.Double p) {
    double rad = Math.toRadians(angle);

    double s = Math.sin(rad);
    double c = Math.cos(rad);

    // translate point back to origin:
    p.x -= cx;
    p.y -= cy;

    // rotate point
    double xnew = p.x * c - p.y * s;
    double ynew = p.x * s + p.y * c;

    // translate point back:
    p.x = xnew + cx;
    p.y = ynew + cy;
    return p;
}

Rotating (-1594,6290) around (-1759,6963) gives (-1086.0 7128.0).

I plotted it with http://www.shodor.org/interactivate/activities/SimplePlot/

-1759,6963
-1594,6290
-1086.0 7128.0

It is obviously wrong, but i can't see why.

Rotating (2,0) around the origin returns (0,2) just fine.

Same with (2,1) around (0,1) => (0,3)

Community
  • 1
  • 1
Heinzlmaen
  • 869
  • 10
  • 20
  • What makes you think it is wrong? – khelwood Nov 04 '15 at 07:26
  • It is very far away from the center of the rotation. Farther than the original point, that isn't how rotation is supposed to work? – Heinzlmaen Nov 04 '15 at 07:37
  • 1
    If you are using SimplePlot to check if the points are the same distance apart, you need to check that the graph's x and y axes are the same scale, otherwise you can't judge the distance over different angles. Why not just calculate the distance manually and check that it is the same? – khelwood Nov 04 '15 at 07:40
  • Thanks, should have looked closer. – Heinzlmaen Nov 04 '15 at 07:45

0 Answers0