How to rotate a vertex around a certain point?

前端 未结 6 1382
南旧
南旧 2020-11-29 04:09

Imagine you have two points in 2d space and you need to rotate one of these points by X degrees with the other point acting as a center.

float distX = Math.a         


        
6条回答
  •  鱼传尺愫
    2020-11-29 04:27

    Assuming you are usign the Java Graphics2D API, try this code -

        Point2D result = new Point2D.Double();
        AffineTransform rotation = new AffineTransform();
        double angleInRadians = (angle * Math.PI / 180);
        rotation.rotate(angleInRadians, pivot.getX(), pivot.getY());
        rotation.transform(point, result);
        return result;
    

    where pivot is the point you are rotating around.

提交回复
热议问题