Reputation: 49
I want to determine the center of a rotated rectangle. This rectangle has to be calculated first (see figure). For this the distance in all four directions from the existing coordinate p(x1, y1) is known (bow, port, star, stern). The orientation of the square is also given in degrees.
The easiest solution for me was to calculate a rectangle around the blue axes and then determine the center of this rectangle. Unfortunately I already have a problem with determining the vertices of the square considering the rotation.
Does anyone know how to calculate the coordinates of the vertices with these inputs (preferred in Java)? If someone knows another simpler approach, I would be very grateful. Thanks a lot!
Upvotes: 0
Views: 1731
Reputation: 49
Alternative formula (source: https://www.researchgate.net/publication/238090180_A_Study_on_the_efficiency_enhancement_of_automatic_radar_tracking_and_analyses_of_marine_traffic_in_Tokyo_Bay):
c_cog = Math.toRadians(course);
double xc = pos_x + (bow - stern) * Math.sin(course) / 2 + (star-port) * Math.sin(course+90) / 2;
double yc = pos_y + (bow - stern) * Math.cos(course)/2 + (star-port) * Math.cos(course+90) / 2;
Upvotes: 0
Reputation: 80107
If star
axis has rotation phi
relative to OX axis, then direction vector for it is
sx, sy = cos(phi), sin(phi) //don't forget about radians and degrees
perpendicular (bow
direction) vector is
bx, by = -sy, sx
So the topmost vertex at the picture has coordinates
tx = px + star * sx + bow * bx
ty = py + star * sy + bow * by
Bottom vertex:
ux = px - port * sx - stern * bx
uy = py - port * sy - stern * by
Rectangle center is middle of these vertices
cx = px + sx * (star - port) / 2 + bx * (bow - stern) / 2
cy = py + sy * (star - port) / 2 + by * (bow - stern) / 2
And reverting b*
variables to sx, sy
:
and accounting for desired angle direction:
cx = px + sx * (star - port) / 2 + sy * (bow - stern) / 2
cy = py - sy * (star - port) / 2 + sx * (bow - stern) / 2
Upvotes: 1