 # Thread: Math issue - How can I determine the distance from a point to the edge of a circle ?

1. ## Math issue - How can I determine the distance from a point to the edge of a circle ?

How can I determine the linear distance from a point to the edge of a circle ?

Please see the following image (I want the distance of the blue lines)
distanceToCircle.png

I have something that works, but uses an active that is moved every frame to the edge of the circle (fastloop for 180 angles) that opens another fastloop that moves another active pixel by pixel until it reaches the point.

It kind of works, but I know it uses more resources then it should... And there should be a math formula for this.

Here I've found some useful links:
https://stackoverflow.com/questions/...r-from-tangent

http://paulbourke.net/dome/fisheye
Not needed right now, but I would really like to know if Angular fisheye (figures 2 and 3) could be calculated with Fusion events   Reply With Quote

2. Supposed you have the Radius (R) of the circle and the Height (H) of the total figure, using the Angle (A) yuo signed here the Blu Line Lenght (Bl) is:
Bl = H - R*Cos(A)  Reply With Quote

3. Here with a little more time to work around it I made this little Example, I tested it just two/three times but it seems to work.
The important thing here is where I put the hotspot for calculus, the circle is in top/middle, the line and active diamond in the center... so the calculus are based between this points.
Change the orientation of the system is just a little bit of work but the idea is similar.

FishEyeTest.mfa

Also I used alterable values to separate the calculus passages, but it is possible to bind them togheter if you need it.  Reply With Quote

4. Thank you very much, I will try it when I get home   Reply With Quote

5. If you want to see, this is the math used

moddedMath.jpg  Reply With Quote

6. Really detailed information, I managed to implement it and works, but it seems that I was wrong in first place.

I really need to use Angular fisheye , not Hemispherical http://paulbourke.net/dome/fisheye (figures 2 and 3)

I would really appreciate if you could help me again with this, or at least with the formulas.
I need to get X2,Y2 from X1,Y1
distanceToCircle2.png  Reply With Quote

7. Edited by me...

I readed better your links and I have some questions (sorry but I have problem with english so I need to read several times to be sure to understand).

Your goal is to know how long is the blue line or to know where is the X coordinate on the bottom depending on the angle? (or oter condition, objects position...)
Because I think I misunderstood the problem reading the links you gave   Reply With Quote

8. I want to know the formula for x2 y2 from that image.
I know the values for x1 y1, height of the total figure, the center of circle and the radius.

Basically I want to "roll" o line of actives alongside a circle.  Reply With Quote

9. Here I am, in this days I was a little busy.

I read the link on the angular fisheye and it is simply a linear correspondence between the X of the projected point and the Angle on the circle.
So all we need to do is write a linear function to link X with the angle A like a straight line equation starting from the left edge of the frame linked to -90 degree, we call this S(0,-90), to the right edge at 90 degree called E(Width-1,90).

The equation to find the angle A on the circle is:

A - Sy = m*(X-Sx) with m=(Ey-Sy)/(Ex-Sy) so if we put the data into the formula and rearrange it we have

A - 90 = (90 + 90)/(Width-1) * X => A = 180/(Width-1) * X - 90

Now that we have the angle A to find the X2 and Y2 point on the circle we simple use Sin and Cos, C is the center point and R the radius

X2 = Cx + R*Sin(A)
Y2 = Cy + R*Cos(A)

NOTE: differently from your image I put the -90 degree on the left and the 90 degree on the right because of the sign of the Sin function, using the original orientation you need to change the value in the S and E point and use a - sign instead of a + in the X2 calculation

NOTE2: to work the circle need to be in the center of the Width Frame, it is possible to think at something different and it is not too difficult but at the moment I have no time, if you need this I can work on it but not now.

Here is the Exemple file

AngularFishEye.mfa  Reply With Quote

10. Here I added a Frame in the last example with the possibility to change the Cx position of the circle by R-Click and drag the red circle.
In this custom version the projection on the bottom plane is not equally linear for all the screen width, but have two different coefficient depending on the position on the left or on the right of Cx.
To do this I split the linear equation in two, the first with S(0,-90)-E(Cx,0) and the second with S(Cx,0)-E(Width-1,90), now you can easily write the two functions as in the previus post.
Then yuo need to use them in two separate event, the first in the event X<=Cx and the second in X>Cx (this is a "piecemeal function"), the Sin/Cos calculus for the point coordinate is the same.

Now you can see the different behavior on the left and right part of the circle depending on wich one is closer to one of the frame borders, on the side closer to the border the point projected on the circunference move faster than the one on the other side.

AngularFishEye.mfa  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•