Follow-up Comment #9, task #4159 (project wormux):
Todo : push this function in vector2.h :
...
static Vector2<T> Intersection(const Vector2<T> & A, const Vector2<T> & B,
const Vector2<T> & C, const Vector2<T> & D) {
double a1, a2, b1, b2, xr, yr;
/*// No intersection possible => compute a fake cross point which is a
avg of this four point
if(A.x == B.x && C.x == D.x) {
double x1, y1, x2, y2;
x1 = (C.x - A.x) + A.x;
y1 = (C.y - A.y) + A.y;
x2 = (B.x - D.x) + B.x;
y2 = (B.y - D.y) + B.y;
return Vector2<T>(static_cast<T>((x1 + x2) / 2), static_cast<T>((y1 +
y2) / 2));
} else if(A.x == B.x) {
a2 = (C.y - D.y) / (C.x - D.x);
b2 = C.y - a2 * C.x;
return Vector2<T>(static_cast<T>(A.x), static_cast<T>(a2 * A.x + b2));
} else if(C.x == D.x) {
a1 = (C.y - D.y) / (C.x - D.x);
b1 = C.y - a2 * C.x;
return Vector2<T>(static_cast<T>(C.x), static_cast<T>(a1 * A.x + b1));
}
// Youhouh ! A normal situation :)*/
a1 = (A.y - B.y) / (A.x - B.x);
a2 = (C.y - D.y) / (C.x - D.x);
b1 = A.y - a1 * A.x;
b2 = C.y - a2 * C.x;
xr = (b2 - b1) / (a1 - a2);
yr = a1 * xr + b1;
return Vector2<T>(static_cast<T>(xr), static_cast<T>(yr));
}
...
Compute the cross point of 2 lines (A, B) and (C, D).
_______________________________________________________
Reply to this item at:
<http://gna.org/task/?4159>
_______________________________________________
Message posté via/par Gna!
http://gna.org/
_______________________________________________
Wormux-gna mailing list
[email protected]
https://mail.gna.org/listinfo/wormux-gna