2022年7月24日

Android Rotate a Point tutorial




    public static double toRadians(double angdeg) {
        return angdeg / 180.0 * Math.PI;
    }

    public  static  PointF rotate_point(double angle, PointF point, PointF center){


        PointF new_pt=new PointF(0,0);
        float x1 = point.x - center.x;
        float 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);

        new_pt.x = (float) (x2 + center.x);
        new_pt.y = (float) (y2 + center.y);

        return  new_pt;

    }




沒有留言:

張貼留言