Mudasar - 1 year ago 98

C++ Question

I have three points, lets say C as a center point while P1 and P2 are two other points.

I have computed angle between C and P1 know as angle1 and c p2 called angle 2.

here is the code I use to compute it

`angle1 = atan2(p1.y - c.y, p1.x - c.x);`

angle2 = atan2(p2.y - c.y, p2.x - c.x);

after that I changed them into degrees by using this.

`if (angle1 >= 0)`

angle1 = angle1 * (180 / PI);

else

angle1 = (angle1 + 2 * PI) * (180 / PI);

if(angle2 >= 0)

angle2 = angle2 * (180 / PI);

else

angle2 = (angle2 + 2 * PI) * (180 / PI);

Then I use this openCv method to compute draw the arc, some time arc is perfect between two point while some times it fills all the circle other than the two points which I post image here.

`radius = sqrt(pow(c.x - p1.x, 2.0) + pow(c.y - p1.y, 2.0));`

ellipse(outPutMat, c, cv::Size(radius, radius), 0, angle1, angle2, Scalar(0, 0, 0), -1, 8, 0);

here are the images

red points are the points, while black is ellipse filled color.

For 1st image agngle1 = 42.1376 while angle2 = 338.962

For 2nd image agngle1 = 152.447 while angle2 = 223.363

2nd image produced right results but first is wrong. I just want to fill area between points.

Answer Source

After short check - it seems that OpenCV function calculates middle angle as `ma = (angle1 + angle2) / 2`

and draws arc through this point.

*Both (-45,45) and (45,-45) give the same 90-degrees arc through zero, both (315,45) and (45,315) give the same 270-degrees arc.*

To get desired result, you have not map negative angle to positive value (`(angle1 + 2 * PI)`

), and use `42`

and `-21`

values in the first case.