0

I am trying to find intersecting Points for Circle with help of this link.

enter image description here

The following note describes how to find the intersection point(s) between two circles on a plane, the following notation is used. The aim is to find the two points P3 = (x3, y3) if they exist.

First calculate the distance d between the center of the circles. d = ||P1 - P0||.

If d > r0 + r1 then there are no solutions, the circles are separate. If d < |r0 - r1| then there are no solutions because one circle is contained within the other. If d = 0 and r0 = r1 then the circles are coincident and there are an infinite number of solutions. Considering the two triangles P0P2P3 and P1P2P3 we can write

a2 + h2 = r02 and b2 + h2 = r12

Using d = a + b we can solve for a,

a = (r02 - r12 + d2 ) / (2 d)

It can be readily shown that this reduces to r0 when the two circles touch at one point, ie: d = r0 + r1 Solve for h by substituting a into the first equation, h2 = r02 - a2 So

P2 = P0 + a ( P1 - P0 ) / d

And finally, P3 = (x3,y3) in terms of P0 = (x0,y0), P1 = (x1,y1) and P2 = (x2,y2), is

x3 = x2 +- h ( y1 - y0 ) / d

y3 = y2 -+ h ( x1 - x0 ) / d http://paulbourke.net/geometry/2circle/

b:=CircleMorph new.
b center: 60@60.
b openInWorld.
b1:=CircleMorph new.
b center: 100@100.
b1 openInWorld.
d:= b1 center - b center. // distance between 2 circles
r1:= (((b center x abs)squared +(b  center y abs)squared)sqrt).
r2:= (((b1 center x abs)squared +(b1  center y abs)squared)sqrt).
r3:= r1+ r2.
(d) > (r3) ifTrue:[Transcript show:'Circles are seprate';cr]

When i compare distance with sum of radius of 2 circles is get distance less than radius of both circles which i know is not true,when circles are seprate Am i calculating radius correctly or not idk there is some problem with this help.

Frank Shearar
  • 17,012
  • 8
  • 67
  • 94
Irfan
  • 303
  • 1
  • 8

1 Answers1

1

One possible solution is this:

| b b1 d r1 r2 r3 |
b := CircleMorph new.
b center: 60@60.
b bounds: (Rectangle origin: 100@40 corner: 40@100).
b openInWorld.
b1 := CircleMorph new.
b center: 100@100.
b bounds: (Rectangle origin: 100@40 corner: 40@100).
b1 openInWorld.
r1 := b bounds width / 2.
r2 := b1 bounds width / 2.
r3 := r1+ r2.
(d < r3)
    ifTrue: [| a h mid |
        a := (r1 squared - r2 squared + d squared) / (2 * d).
        h := (r1 squared - a squared) sqrt.
        mid := (b1 center x - b center x) @ (b1 center y - b center y).
        {(mid x + (h * (b1 center y - b center y))) @ (mid y - (h * (b1 center x - b center x))).
        (mid x - (h * (b1 center y - b center y))) @ (mid y + (h * (b1 center x - b center x)))}]
    ifFalse: ['separate']

You'll want to check my arithmetic. (Update: I hadn't used the point between the two circle centres to calculate the points.)

Frank Shearar
  • 17,012
  • 8
  • 67
  • 94
  • Also d is not a distance, it's a point representing x@y coordinates of vector b to b1, use (b1 center dist: b center). – aka.nice Sep 12 '12 at 19:17
  • Or `(LineSegment from: b1 center to: b center) length`. – Frank Shearar Sep 12 '12 at 20:59
  • Thanks you i get it now, what if distance= radius1 + radius2 (d=r1+r2) how do i get just one point of intersection??? – Irfan Sep 14 '12 at 01:10
  • You will need to special-case, perhaps with a `(d - (r1 + r2)) < 0.001 ifTrue: [...]` or similar. – Frank Shearar Sep 14 '12 at 06:25
  • Here is what i did to get just one Intersection point when distance is equal to both circle radius '(d)=(r1+r2) ifTrue[|m| m:=((b1 center x + b center x)/2)@ ((b1 center y + b center y)/2)]' do you think its true center point can be intersection point??? – Irfan Sep 16 '12 at 00:40
  • Consider two circles with equal radius just touching each other. Join their centres. The circles will touch each other on the midpoint of that line. If one circle has twice the radius as the other, the circles will touch on the line 2/3 of its length away from the larger circle, and so on. – Frank Shearar Sep 16 '12 at 08:56
  • Hi can u help me with like creating a method for radius. I want to create a separate radius method which i can use any time to calculate radius of any given circle. – Irfan Sep 23 '12 at 01:15
  • 1
    The radius is just half the width of the circle's `bounds`. So it's just `radius\n^ self bounds width / 2` – Frank Shearar Sep 23 '12 at 08:49
  • Thanks for the helping i am still trying to learn all this, I wanna add an intersection method too how do i do that, which would do all the condition check and would give resulting points of intersection. – Irfan Sep 23 '12 at 18:43
  • You're asking lots of different questions. It's easier to answer these by you asking separate questions, rather than asking through comments. – Frank Shearar Sep 23 '12 at 19:35