Ask Your Question
1

unable to determine angle because of points from line

asked 2015-08-04 07:34:34 -0600

Saghir A. Khatri gravatar image

updated 2015-10-06 09:16:42 -0600

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 image description

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,

edit retag flag offensive close merge delete

Comments

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 gravatar imagethdrksdfthmn ( 2015-08-04 08:53:55 -0600 )edit

@thdrksdfthmn please elaborate about tangent. Thanks

Saghir A. Khatri gravatar imageSaghir A. Khatri ( 2015-08-05 03:11:39 -0600 )edit

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

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-08-05 06:52:25 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-08-05 09:12:53 -0600

chr0x gravatar image

updated 2015-08-05 09:40:28 -0600

You could create a Point2f (2 dimensions float) in the center of each of the smaller sides of your rectangle:

o o x o o  ---> x = point_a
 o o o o
  o o o
   o o
    x      ---> x = point_b

(Above, "x" represents the points). This way, you will get a line between those points:

o   x   o  
 o  |  o
  o | o
   o|o
    x

To calculate that line angle in radians:

double rad_angle = atan(point_a/point_b);

If you want the angle in degrees:

double degrees_angle = rad_angle * 180/CV_PI;

Cheers!

edit flag offensive delete link more

Comments

Hi @chr0x i want use the ascii drawing tool in my c++ comments , would you tell me what is the name of the tool you used to draw this shapes thanks

essamzaky gravatar imageessamzaky ( 2015-08-06 02:18:56 -0600 )edit
2

That is no tool ^_^ but just adding o, x and | symbols at the right position and then making it a code block. An example:

xx - - - xx
 xx -- xx
   x o x
     x
StevenPuttemans gravatar imageStevenPuttemans ( 2015-08-06 03:52:31 -0600 )edit

Thanks @StevenPuttemans , As you see your Ascii drawing is not well formated , while the original drawing are very accurate , so i think it's ascii drawing tool , i have some code which has very difficult drwaings and very difficult to be done by manual draw

essamzaky gravatar imageessamzaky ( 2015-08-11 08:29:57 -0600 )edit
1

You can edit topics on the forum, do not mix up comments with posts, which have a complete different layout editor behind them and sometimes screw up code. I just copied the example from the first part of the answer below, to illustrate

o o x o o  ---> x = point_a
 o o o o
  o o o
   o o
    x      ---> x = point_b
StevenPuttemans gravatar imageStevenPuttemans ( 2015-08-12 03:35:34 -0600 )edit
1

^_^ here you can see that it does work, as long as you position well. And a small edit made mine perfect again :D

StevenPuttemans gravatar imageStevenPuttemans ( 2015-08-12 03:35:55 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-08-04 07:34:34 -0600

Seen: 800 times

Last updated: Aug 05 '15