http://paulbourke.net/geometry/2circle/ Solved this with help of few people on here, This code will get the point of intersection for two circles
Here is my workspace code
|b b1 r r1 r2 d |
b1:= CircleAnimeMorph new. " CircleAnimeMorph is my new class"
b1 center: 100@100.
b1 openInWorld.
b:= CircleAnimeMorph new.
b openInWorld.
d:= b1 center dist: b center. "distance between 2 circles"
r:=b1 bounds width /2. "radius of first circle"
r1:=b bounds width/2. "radius of second Circle"
r2:=r + r1 .
(d )< (r2)
ifTrue: [| a h mid c c1 myPen h1 h2 mx my mc mc1|
a := (r squared - r1 squared + d squared) / (2 * d).
h := (r squared - a squared) sqrt.
h1:= b center y - b1 center y.
h2:= b center x - b1 center x.
mx:=a * (b center x - b1 center x)/d.
my:=a* (b center y - b1 center y)/d.
mid := ((mx)+(b1 center x) @ (b1 center y )+(my) ) " calculates mid point between 2 intersecting circles (p2)"
{
mc:=(h * h1)/d.
mc1:=(h * h2)/d.
c:=(mid x + mc )@ (mid y - mc1 )."Actual Intersecting points"
c1:=(mid x -mc) @ (mid y + mc1 )."Actual Intersecting points"
Transcript show: (c); show: (c1); cr
}.
myPen := Pen new.
myPen color: Color red.
myPen putDotOfDiameter: 5 at: mid.
myPen putDotOfDiameter: 5 at: c1.
myPen putDotOfDiameter: 5 at: c. ].
Can any one help me make this a methods ,I wanna make this a intersection method which will do all this when i say
b1 intersection:b.
should do all of this and draw colored dots at intersecting points
It sounds like you just want to add a new method to your class. Open up a Browser, navigate to CircleAnimeMorph
, click somewhere in the method category pane (that's the second pane from the right), click in the code pane (the lower half of the Browser) and add
intersection: aCircleAnimeMorph
"And here, put your workspace code, but remove the initialisation stuff,
change 'b' to 'self' and 'b1' to 'aCircleAnimeMorph',
and make sure you actually return the values. Don't forget to remove
the Transcript and drawing logic."