3

私が持って いるのは、ステージ上の 2 つの円、circ1 と circ2 です。circ1 の半径は 60、circ2 の半径は 30 です。

circ2 は、再生中にステージ上でドラッグできます。

私が欲しい のは、共通の外側の接線で円を結ぶ 2 本の線です。これは、古いポスターをインタラクティブなファンボックスに変えることに取り組んでいます。ここにポスターへのリンクがあります。これは、私の言いたいことを理解するのに役立つかもしれません (ただし、今のところ、2 つの円についてのみ考えます)。

問題: ペンと紙を使って共通点を見つける方法は理解できますが、これを Flash が理解できるように表現する方法を考えようとすると、私の頭は崩壊してしまいます。ActionScript を使用してこれを実現する方法がわかりません。

私が試したこと: 私は周りを見回しましたが、これは私が達成しようとしていることに最も近いものです(サンプルアプリはページの下部からダウンロードできます). 唯一の違いは、これには必要のない内部接線が含まれていることです。

残念ながら、このソースは Java で書かれており、最善を尽くしたにもかかわらず、AS3 に移植するには十分な理解がありません。

これまでのところ、自分で達成できたのは、各円の中心にポイントを定義することだけであり、フラッシュで変数の方程式を解くことはできないことに気付きました。次に、ここから先に進む方法を理解するために、グーグルで数時間を費やしました。

これは、今週末に予定されている学校のプロジェクトの作業です。ここで噛み切れないほど噛んだかもしれませんが、今から引き返すには遅すぎます。

前もって感謝します!

4

2 に答える 2

4
function DrawTangents(p1 : Point, r1 : Number, p2 : Point, r2 : Number) : void {
    var dx = p2.x - p1.x;
    var dy = p2.y - p1.y;
    var dist = Math.sqrt(dx*dx + dy*dy);

    this.graphics.drawCircle(p1.x, p1.y, r1);
    this.graphics.drawCircle(p2.x, p2.y, r2);

    if (dist <= Math.abs(r2 - r1)) {
        // The circles are coinciding. There are no valid tangents.
        return;
    }

    // Rotation from the x-axis.
    var angle1 = Math.atan2(dy, dx);

    // Relative angle of the normals. This is equal for both circles.
    var angle2 = Math.acos((r1 - r2)/dist);

    this.graphics.moveTo(p1.x + r1 * Math.cos(angle1 + angle2),
                         p1.y + r1 * Math.sin(angle1 + angle2));
    this.graphics.lineTo(p2.x + r2 * Math.cos(angle1 + angle2),
                         p2.y + r2 * Math.sin(angle1 + angle2));

    this.graphics.moveTo(p1.x + r1 * Math.cos(angle1 - angle2),
                         p1.y + r1 * Math.sin(angle1 - angle2));
    this.graphics.lineTo(p2.x + r2 * Math.cos(angle1 - angle2),
                         p2.y + r2 * Math.sin(angle1 - angle2));
}
于 2012-08-20T12:34:53.840 に答える
3

2つの円が同じサイズであると仮定して、2つの円について説明したことを行う作業コードを次に示します。それ以外の場合は、接点が円の中心を結ぶ線に垂直な線上にあると仮定するため、近似値です。

var point1 : Point = new Point(100, 100);
var point2 : Point = new Point(300, 50);
var radius1 : int = 60;
var radius2 : int = 30;

// if you draw a line from the first circle origo to
// the second origo, this is the angle of that line
var ang : Number = Math.atan2(point2.y - point1.y, point2.x - point1.x);

// find the first point on the circumference that is orthogonal
// to the line intersecting the two circle origos
var start1 : Point = new Point(point1.x + Math.cos(ang + Math.PI / 2) * radius1, 
                               point1.y + Math.sin(ang + Math.PI/2)* radius1);
var end1 : Point = new Point(point2.x + Math.cos(ang + Math.PI / 2) * radius2, 
                             point2.y + Math.sin(ang + Math.PI/2)* radius2);

// find the second point on the circumference that is orthogonal
// to the line intersecting the two circle origos
var start2 : Point = new Point(point1.x + Math.cos(ang - Math.PI / 2) * radius1, 
                               point1.y + Math.sin(ang - Math.PI/2)* radius1);
var end2 : Point = new Point(point2.x + Math.cos(ang - Math.PI / 2) * radius2,
                             point2.y + Math.sin(ang - Math.PI/2)* radius2);

// draw everything on the stage
this.graphics.lineStyle(1, 0x0);
this.graphics.drawCircle(point1.x, point1.y, radius1);
this.graphics.drawCircle(point2.x, point2.y, radius2);

this.graphics.moveTo(start1.x, start1.y);
this.graphics.lineTo(end1.x, end1.y);

this.graphics.moveTo(start2.x, start2.y);
this.graphics.lineTo(end2.x, end2.y);
于 2012-08-20T09:59:46.393 に答える