I create a Canvas object (lines, vertices, a triangle, ...), and I would like to apply rotation around a point to them.
I canβt use the rotate () method of Canvas because the points are attached to the GeoPoint on the map, so if I use the rotate () method, all the maps rotate ...
The problem is that Canvas needs Point (int, int) and applying rotation creates a double due to the cos and sin functions. Therefore, when I apply rotation to all points, because you are double-binding to int, I have some kind of graphical problem that happens ...
So, I am looking for the best solution.
Here is my rotation code:
public Point rotatePoint(Point pt, Point center)
{
this.angle = ((this.angle/180)*Math.PI);
double cosAngle = Math.cos(this.angle);
double sinAngle = Math.sin(this.angle);
pt.x = center.x + (int) ((pt.x-center.x)*cosAngle-(pt.y-center.y)*sinAngle);
pt.y = center.y + (int) ((pt.x-center.x)*sinAngle+(pt.y-center.y)*cosAngle);
return pt;
}
source
share