ここでは線分間の交差点について、stackowerflowで多くの質問があります。申し訳ありませんが、交差点を計算する方法を理解するためには助けが必要です。私はここでいくつかの質問を読んで、他のウェブサイトのいくつかの例を見てきましたが、私はまだ混乱しており、それを手に入れません!私は物事の仕組みがなくてもコードをコピー&ペーストするのは好きではありません。線分間の交点の計算
これまでAx、Ay、Bx、By、Cx、Cy、Dx、Dyのような各線分の点を比較するつもりです。誰かが私が計算しようとしていることを私に説明してもらえますか、交差点があれば計算の結果はどうなりますか?
これは私が見たサンプルコードの1つです。線が交差するかどうかを知るために、交差点は必要ないと思います。
public static Point lineIntersect(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
double denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
if (denom == 0.0) { // Lines are parallel.
return null;
}
double ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3))/denom;
double ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3))/denom;
if (ua >= 0.0f && ua <= 1.0f && ub >= 0.0f && ub <= 1.0f) {
// Get the intersection point.
return new Point((int) (x1 + ua*(x2 - x1)), (int) (y1 + ua*(y2 - y1)));
}
return null;
}
このコード例のように中央値を計算する必要がありますか?
For lines through points (x0,y0) and (x1,y1), let xm = (x0+x1)/2, ym = (y0+y1)/2 (median of line segment).
Then a = (y1-y0) and b = (x0-x1).
If you evaluate c = a(x-xm)+b(y-ym), c=0 for (x,y) on the line, and the sign(c) tells you which side a point is on
あなたのポイントは整数かフロートですか? –