I have a new class for Circle Morph which has a step method that increases the diameter.
step self extent: self extent +1. (self extent )>(400@400) ifTrue: [self stopStepping] b:=CircleAnimeMorph new // new class for Circle Morph b openInWorld b startStepping b1:CircleAnimeMorph new b1 openInWorld b1 startStepping. So when these both Circles meet i wanna get the Intersecting point,idk how to implement this can any one help? |
On 2012-09-05, at 01:22, irfankhan1 <[hidden email]> wrote: > I have a new class for Circle Morph which has a step method that increases > the diameter. > > > step > > self extent: self extent +1. > (self extent )>(400@400) ifTrue: [self stopStepping] > > > b:=CircleAnimeMorph new // new class for Circle Morph > b openInWorld > b startStepping > b1:CircleAnimeMorph new > b1 openInWorld > b1 startStepping. > > > > > So when these both Circles meet i wanna get the Intersecting point,idk how > to implement this can any one help? see all the details here: http://mathworld.wolfram.com/Circle-CircleIntersection.html basically you first check if both radii overlap, once you know that you can do the detailed trigonometry to get the intersection points. As a first step I would implement a #intersectsCircle: aCircle method. The I think it makes most sense to put the two circles into a surrounding morph which will take care of the intersection check. Simply override the step method there and perform the tests. |
In reply to this post by irfankhan1
I solved this intersection of points using this link http://paulbourke.net/geometry/2circle/
Here is my workspace code |b b1 r r1 r2 d d1| b1:= CircleAnimeMorph new. 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 |
What i would recommend is to not mix morphs and math.
Put the implementation into clean and separate class(es), which takes 2 circles (like point + raduis pair for each), and provides an interface for testing whether circles intersect as well as finding intersection point(s). Then when you done, you can use it anywhere, including morphs. On 24 September 2012 01:54, irfankhan1 <[hidden email]> wrote: > I solved this intersection of points using this link > http://paulbourke.net/geometry/2circle/ > <http://paulbourke.net/geometry/2circle/> > > Here is my workspace code > |b b1 r r1 r2 d d1| > > b1:= CircleAnimeMorph new. > 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 > > > > > -- > View this message in context: http://forum.world.st/Get-the-point-of-Intersection-for-Morphs-tp4646066p4648614.html > Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com. > -- Best regards, Igor Stasenko. |
Hi,
My Pharo has no CircleAnimeMorph (yet). And you code seems to have a } missing? Peter 2012/9/24 Igor Stasenko <[hidden email]> What i would recommend is to not mix morphs and math. |
Free forum by Nabble | Edit this page |