tags:

views:

56

answers:

2

Hello,

I have the following problem, I am trying to find the following distances (F1 and F2): circle

This is what I have as of now:

def FindArrow(self, X1, Y1, X2, Y2, X3, Y3):
    self.X1 = float(X1)
    self.Y1 = float(Y1)
    self.X2 = float(X2)
    self.Y2 = float(Y2)
    self.X3 = float(X3)
    self.Y3 = float(Y3)
    #center coords of the circle
    self.Xc = None
    self.Yc = None
    #radius
    self.R = None

    #F1 and F2
    self.FAB = None
    self.FBC = None

    #check if the coordinates are collinear
    invalide = self.X1 * (self.Y2 - self.Y3) + self.X2 * (self.Y3 - self.Y1) + self.X3 * (self.Y1 - self.Y2)
    if (invalide == 0):
        return

    #get the coords of the circle's center
    s = (0.5 * ((self.X2 - self.X3)*(self.X1 - self.X3) - (self.Y2 - self.Y3) * (self.Y3 - self.Y1))) / invalide

    self.Xc = 0.5 * (self.X1 + self.X2) + s * (self.Y2 - self.Y1)
    self.Yc = 0.5 * (self.Y1 + self.Y2) + s * (self.X1 - self.X2)

    #get the radius
    self.R = math.sqrt(math.pow(self.Xc - self.X1, 2) + math.pow(self.Yc - self.Y1, 2))

Until here everything seems to work, now what would be the next steps to get F1 and F2 ?

EDIT: Both of the answers (Tomer and inerjay) seem to work for the first image, but I have tried the following image and it does not work anymore :

circle2

+1  A: 

If you have the circle's radius, you can use Pythagoras' Theorem to get the distance from the circle's center to the segment P2-P3 (look at the triangle with its vertices at: P2, the circle's center, and the middle of P2-P3). Then subtract that from the radius to get F2. Same method to get F1.

Edit: If you call x the distance between the center and the segment P2-P3, then F2 is either R-x (as in the first image), or R+x (as in the second image). It depends on how you define F1 and F2.

If you define F1 and F2 so that they always go outward from the triangle P1-P2-P3 (this fits both your examples), then F2 = R-x if the circle's center is on the same side of P2-P3 as P1, and F2 = R+x if P1 and the circle's center are on opposite sides of P2-P3.

interjay
check new image, it doesn't seem to work in that case
Enriquev
@Enriquev: Then there's no way to answer your question until it's better specified. I updated my answer for one possible interpretation.
interjay
+1 for the fix.
Tomer Vromen
this seems to work, now I need code to check this? anyways, I will code it and try it with my data, if everything passes then you solved me a huge headache :-)
Enriquev
A: 

If I understand correctly, the segments F1,F2 point towards the cirlce's center. Mark the circle's center O, and build the triangle whose vertices are (P1,P2,O). You know all the lengths of the edges, so you can calculate the triangle's area S (see here). And since you know the area, you also know the length of the triangle's height, which is the continuation of F1 to O:

S = 0.5*dist(P1,P2)*height

Then F1 = radius - height, and same goes for F2.

Tomer Vromen
check new image, it doesn't seem to work in that case
Enriquev
interjay's fix looks correct
Tomer Vromen