From 785b1aa7486d07dc4e73e0208a1bd2196693b159 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 1 Nov 2020 11:32:22 +0100 Subject: [PATCH] arb fixup --- hyperpoint.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hyperpoint.cpp b/hyperpoint.cpp index 54760e3f..a5c8ae47 100644 --- a/hyperpoint.cpp +++ b/hyperpoint.cpp @@ -1485,4 +1485,24 @@ EX hyperpoint lerp(hyperpoint a0, hyperpoint a1, ld x) { return a0 + (a1-a0) * x; } +EX hyperpoint linecross(hyperpoint a, hyperpoint b, hyperpoint c, hyperpoint d) { + a /= a[LDIM]; + b /= b[LDIM]; + c /= c[LDIM]; + d /= d[LDIM]; + + ld bax = b[0] - a[0]; + ld dcx = d[0] - c[0]; + ld cax = c[0] - a[0]; + ld bay = b[1] - a[1]; + ld dcy = d[1] - c[1]; + ld cay = c[1] - a[1]; + + hyperpoint res; + res[0] = (cay * dcx * bax + a[0] * bay * dcx - c[0] * dcy * bax) / (bay * dcx - dcy * bax); + res[1] = (cax * dcy * bay + a[1] * bax * dcy - c[1] * dcx * bay) / (bax * dcy - dcx * bay); + res[2] = 1; + return normalize(res); + } + }