unable to determine angle because of points from line
I have an image from which i have created some lines. I have saved starting and end points of line. Lines are basically long side of rectangle that is bounding a white blob in image. Rectangles are placed in some circle. Image is shown as below
Issue is when rectangle is formed in the lower part of circle, Starting point can be thought as the lower most Point of the circle i.e near the edge of circle, but when Rectangle is formed in the upper part of the circle as shown in the last dial of the image it is difficult to find out which point to choose as the starting point to find out the starting point which is near center of the dial.
Is there any workaround on how i can swap points of line in upper region of circle. Kindly guide me as i am out of ideas with this now.
Here is code to select longest side of rectangle and printing its points
int maxIndex = 0;
for (int a = 1; a < length.length; a++){
double newnumber = length[a];
if ((newnumber > length[maxIndex])){
maxIndex = a;
}
}
System.out.println("Start= "+pts[maxIndex].toString()+" End= "+pts[(maxIndex+1)%4].toString()+", Length="+length[maxIndex]);
Regards,
I see rectangles there, more, RotatedRect, Have you thought to take in consideration its center? Or just use both the starting and ending points, so if the lowest is in the top part of in the circle, then the rect is in the top part of the circle and if the highest is in the bottom, then the rect is in the bottom part of the circle [the (x=0, y=0) is in the top-left corner]? Or you can use the tangent, it is invariant to the position of the points...
@thdrksdfthmn please elaborate about tangent. Thanks
You have the two points, so you can compute the tangent of the line that passes through the 2 points, it is the same, no matter where the points are (see this). Now you can do an approximation of the hour. Your problems will be when tangent is 0 or infinite (y1==y2, or x1==x2) and you need to know if it is left, right, up or down, and that you can compute by taking the mean of the 2 coordinates (x, or y) and compare it with the one of the circle's center