0

http://paulbourke.net/geometry/2circle/ 在少数人的帮助下解决了这个问题,这段代码将获得两个圆的交点

这是我的工作区代码

    |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. ].

谁能帮我把它做成一个方法,我想把它做成一个交集方法,当我说的时候它会做这一切

    b1 intersection:b. 

应该做所有这些并在交叉点绘制彩色点

4

1 回答 1

0

听起来您只想为您的课程添加一个新方法。打开浏览器,导航到CircleAnimeMorph,单击方法类别窗格中的某处(即右侧第二个窗格),单击代码窗格(浏览器的下半部分)并添加

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."
于 2012-09-24T17:19:51.460 回答