これが私がこれを解決した方法です。BとCはあなたが定義したものと同じです。私は、ポイントAを最初の行の最後の完全なセグメントの終わりと呼んでいます。(曲がる前の最後の点)中心がAで、半径=セグメントの長さの円を描く場合、その円が線分BCと交差する場所は、角を切るAからの線の端点(Dと呼びます)です。 。その点を見つけるために、私はきちんとしたヘルパー関数を見つけました。それほど長くはありません。簡単にするために、ここに貼り付けています。
/*---------------------------------------------------------------------------
Returns an Object with the following properties:
enter -Intersection Point entering the circle.
exit -Intersection Point exiting the circle.
inside -Boolean indicating if the points of the line are inside the circle.
tangent -Boolean indicating if line intersect at one point of the circle.
intersects -Boolean indicating if there is an intersection of the points and the circle.
If both "enter" and "exit" are null, or "intersects" == false, it indicates there is no intersection.
This is a customization of the intersectCircleLine Javascript function found here:
http://www.kevlindev.com/gui/index.htm
----------------------------------------------------------------------------*/
function lineIntersectCircle(A : Point, B : Point, C : Point, r : Number = 1):Object {
var result : Object = new Object ();
result.inside = false;
result.tangent = false;
result.intersects = false;
result.enter=null;
result.exit=null;
var a : Number = (B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y);
var b : Number = 2 * ((B.x - A.x) * (A.x - C.x) +(B.y - A.y) * (A.y - C.y));
var cc : Number = C.x * C.x + C.y * C.y + A.x * A.x + A.y * A.y - 2 * (C.x * A.x + C.y * A.y) - r * r;
var deter : Number = b * b - 4 * a * cc;
if (deter <= 0 ) {
result.inside = false;
} else {
var e : Number = Math.sqrt (deter);
var u1 : Number = ( - b + e ) / (2 * a );
var u2 : Number = ( - b - e ) / (2 * a );
if ((u1 < 0 || u1 > 1) && (u2 < 0 || u2 > 1)) {
if ((u1 < 0 && u2 < 0) || (u1 > 1 && u2 > 1)) {
result.inside = false;
} else {
result.inside = true;
}
} else {
if (0 <= u2 && u2 <= 1) {
result.enter=Point.interpolate (A, B, 1 - u2);
}
if (0 <= u1 && u1 <= 1) {
result.exit=Point.interpolate (A, B, 1 - u1);
}
result.intersects = true;
if (result.exit != null && result.enter != null && result.exit.equals (result.enter)) {
result.tangent = true;
}
}
}
return result;
}
これは、いくつかのプロパティを持つオブジェクトを返す関数であるため、コードに実装するのは非常に簡単です。あなたはそれに3つのポイントと半径を渡す必要があります。最初の2つのポイントは、上記で定義したBとC、および最初に説明したポイントAです。ここでも、半径はセグメントの長さです。
//create an object
var myObject:Object = lineIntersectCircle(pointB, pointC, pointA, segmentLength);
それでおしまい!点Dの座標(上記を参照)は次のとおりです。(myObject.exit.x, myObject.exit.y)