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.
应该做所有这些并在交叉点绘制彩色点
答案 0 :(得分:0)
听起来你只想在课堂上添加一个新方法。打开浏览器,导航到CircleAnimeMorph
,单击方法类别窗格中的某个位置(右侧的第二个窗格),单击代码窗格(浏览器的下半部分)并添加< / p>
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."