biVector forum

Is line crossing a bounded plane

I am looking for a way to determine if a line cross a plane within a contour (red mirror on the attached image)

@charpelletier Just to make sure I understand what the question is: Is it the same as asking whether the line intersects the red quadrilateral?

Yes, in order to find whether the corner light
rays will bounce on the mirror (red plane)

@charpelletier In general, let \{P_i\}, 0\leq i < n, be the normalized vertices of a convex polygon K in 3D (e. g., the red mirror here, n=4).

Let L be the line to test.

Define B_i := P_i \vee P_{(i+1)\%n}. These are the oriented boundary lines of the polygon.

Define k_i := B_i \vee L (= \| B_i \wedge L \|_\infty). k_i is the oriented volumes of the tetrahedron formed by joining the vertices of the i^{th} oriented edge segment of K and an oriented unit line segment lying on L (assuming L has been normalized).

Then L intersects the interior of K \iff all k_i are the same sign.

2 Likes

What cgunn3 said in terms of very simple code for a triangle without any loops or variables:
Does line L intersect the inside of triangle ABC?
var intersects = ((A&B & L).s > 0) == ((B&C & L).s > 0) && ((B&C & L).s > 0) == ((C&A & L).s > 0);
if (intersects) {...}
(of course, this is a bit verbose so I do suggest using variables and loops)
I’m trying to practice a bit myself now and this helped, thank you :slight_smile:

Edit: Previously posted a non-working answer - forgot to take the s parameter, oops!

My advice: Be careful that the sign check you are using is correct – if the polygon vertices occur in the reverse order, all the k_i values will flip sign – that’s why it’s safer I think to check that they are all the same sign.

The “equal signs” part was totally fine but the sign check was definitely wrong, oops! Fixed it and edited my original comment. Making an interactive toy helped find the issue (which was that I didn’t take the scalar part and instead compared the multivector against a scalar)

Thank you, what you proposed does work.

I was, without success, trying to follow cgunn3 proposition, and I got stuck on ||B_i \wedge L ||\infty, that I was trying to implement the way shown below… There is a lot of know how that I’m missing, like the purpose of : .s .

var b0a = (M2_A & M2_B) // boundary lines
var b1a = (M2_B & M2_D)
var b2a = (M2_D & M2_A)

var ell = R_M1_C.Normalized // a ray of light

var k0 = (b0a ^ ell), //oriented volumes
k1 = (b1a ^ ell),
k2 = (b2a ^ ell)

var lin0 = Math.sqrt((k0.e01)**2 + (k0.e02)**2 + (k0.e03) **2), // attempt to get the infinite norm
lin1 = Math.sqrt((k1.e01)**2 + (k1.e02)**2 + (k1.e03) **2),
lin2 = Math.sqrt((k2.e01)**2 + (k2.e02)**2 + (k2.e03) **2)

Yes, it can be a challenge to translate the mathematical language into ganja.js code or other languages.

The x.s syntax extracts the scalar part of the multivector x, while x.e0123 extracts the pseudoscalar part.

The expression in parentheses (= \| B_i \wedge L\|_\infty) isn’t necessary to implement the code. I included it as an alternative in case readers are surprised to find a join operator ; the usual procedure is to use the wedge and then extract the magnitude of it, which mathematically is done with the ideal norm, in ganja.js can be achieved using x.e0123.

Thank you, Tested ok, both methods give the same result…I still need, though, to keep investigating the underneath meaning of all that, but this will be, I guess, the subject of another post…Regards,

var test_a = (M2_A & M2_B) ^ L //.e0123
var test_b = (M2_A & M2_B) & L //.s

image

Something seems off in your inspection - I think a volume should be a scalar and nothing else.
Are you sure your points are actually points and your lines are lines? Or am I wrong and I missed something?
Here’s my example inspection. Note that points only have trivector and lines only bivector components.
image

I can’t tell why I’ve got those numbers previously, but here is what I’m getting now, while they boundary detection algorithm is working fine.
image
image