Commit 90dc2f97 authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Model: updated LineIntersection

parent 191cb584
...@@ -5,78 +5,32 @@ component LineIntersection{ ...@@ -5,78 +5,32 @@ component LineIntersection{
in Q^{4,1} lineB, in Q^{4,1} lineB,
out Q^{2,1} point, out Q^{2,1} point,
out B intersects; out B intersects;
implementation Math{
Q n1 = (lineA(1,1)-lineA(3,1))*(lineB(2,1)-lineB(4,1))-(lineA(2,1)-lineA(4,1))*(lineB(1,1)-lineB(3,1));
Q n2 = (lineA(1,1)-lineA(3,1))*(lineB(2,1)-lineB(4,1))-(lineA(2,1)-lineA(4,1))*(lineB(1,1)-lineB(3,1));
implementation Math{
Q Ax = lineA(3,1) - lineA(1,1);
Q Ay = lineA(4,1) - lineA(2,1);
Q Bx = lineB(1,1) - lineB(3,1);
Q By = lineB(2,1) - lineB(4,1);
Q Cx = lineA(1,1) - lineB(1,1);
Q Cy = lineA(2,1) - lineB(2,1);
Q n1 = Ay*Bx - Ax*By;
Q cutoff = 0.00000001; Q cutoff = 0.00000001;
B res = False;
if (abs(n1) > cutoff) && (abs(n2) > cutoff)
Q z1 = (lineA(1,1)*lineA(4,1)-lineA(2,1)*lineA(3,1))*(lineB(1,1)-lineB(3,1))-(lineA(1,1)-lineA(3,1))*(lineB(1,1)*lineB(4,1)-lineB(2,1)*lineB(3,1)); //if lines are not parallel(ish)
Q z2 = (lineA(1,1)*lineA(4,1)-lineA(2,1)*lineA(3,1))*(lineB(2,1)-lineB(4,1))-(lineA(2,1)-lineA(4,1))*(lineB(1,1)*lineB(4,1)-lineB(2,1)*lineB(3,1)); if (abs(n1) > cutoff)
point(1,1) = z1/n1; Q alpha = (By * Cx - Bx * Cy) / n1;
point(2,1) = z2/n2; if (alpha >= cutoff) && (alpha <= 1)
Q beta = (Ax * Cy - Ay * Cx) / n1;
if abs(point(1,1)) < cutoff if (beta >= cutoff) && (beta <= 1)
point(1,1) = 0; res = True;
end point(1,1) = lineA(1,1) + alpha * Ax;
point(2,1) = lineA(2,1) + alpha * Ay;
if abs(point(2,1)) < cutoff end
point(2,1) = 0; end
end
Q xmin1;
Q xmax1;
Q ymin1;
Q ymax1;
Q xmin2;
Q xmax2;
Q ymin2;
Q ymax2;
//bounding box 1
if lineA(1,1) >= lineA(3,1)
xmax1 = lineA(1,1);
xmin1 = lineA(3,1);
else
xmax1 = lineA(3,1);
xmin1 = lineA(1,1);
end
if lineA(2,1) >= lineA(4,1)
ymax1 = lineA(2,1);
ymin1 = lineA(4,1);
else
ymax1 = lineA(4,1);
ymin1 = lineA(2,1);
end
//bounding box 2
if lineB(1,1) >= lineB(3,1)
xmax2 = lineB(1,1);
xmin2 = lineB(3,1);
else
xmax2 = lineB(3,1);
xmin2 = lineB(1,1);
end
if lineB(2,1) >= lineB(4,1)
ymax2 = lineB(2,1);
ymin2 = lineB(4,1);
else
ymax2 = lineB(4,1);
ymin2 = lineB(2,1);
end
B onLineA = (xmin1 <= point(1,1)) && (point(1,1) <= xmax1) && (ymin1 <= point(2,1)) && (point(2,1) <= ymax1);
B onLineB = (xmin2 <= point(1,1)) && (point(1,1) <= xmax2) && (ymin2 <= point(2,1)) && (point(2,1) <= ymax2);
intersects = onLineA && onLineB;
else
point(1,1) = 0;
point(2,1) = 0;
intersects = False;
end end
intersects = res;
} }
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment