[nevermind] sorry...

Started by
7 comments, last by Christopher Harris 18 years, 3 months ago
I know I've run across the equation for this before, but I can't quite find it. I'm looking for the equation that takes 3 points (a line and a testing point) and returns a positive or negitive value depending on what side of the line it is on. I also recall there being a 3D version of this code? I really need the 2D version. Also, could someone provide some explaination of what the equation actually does (because as by now I've most likely forgotten HOW it does what it does). Thanks in advance! [Edited by - Christopher Harris on January 21, 2006 8:32:51 PM]
Advertisement
Could you better define the result you are expecting? In my mind, having a point on one side or another of an arbitrary line is undefined - so I would be expecting some other constraint.

However, for 3-D, I would look into backface culling, which performs computation that is similar to results that you are seeking by checking if the polygon is facing away or toward the viewer by an if( result + or - ) bent.

Hope this is in some way helpful.
^sf.
you are looking for the famous vector dotproduct. and as the name sounds, you need two vectors in order to calculate it ( be it 2D vectors or 3D ones )
---novocaine thru yer veinz
Here's the 2d version:
Vector2 diff = P-A;Vector2 dir = B-A;Vector2 normal(-dir.y,dir.x);float d = dot(diff,normal);if (d < 0.0f) {    // P is on one side of AB} else {    // P is on the other side of AB}
You can tweak the test to include a 'P is on the line AB' if needed. Also, there isn't a corresponding 3d version because there isn't really a 'side' of a line in 3d.

[Edit: Actually, the 'corresponding 3d version' is a point-plane test; lines and planes are each hyperplanes in their respective dimensions.]
jyg mate, he was actually asking around about the dot() function itself.

Christopher, you would better take a look here
---novocaine thru yer veinz
Quote:Original post by benishor
jyg mate, he was actually asking around about the dot() function itself.
Hehe, we're already going back and forth in the quaternion thread, but (quoted from the OP):
Quote:I'm looking for the equation that takes 3 points (a line and a testing point) and returns a positive or negitive value depending on what side of the line it is on.
It sounds to me like he's asking about a 3d point-line test, no?
You are probably right. I figured that he would know how to use the dotproduct :)
---novocaine thru yer veinz
Sweet! Looks like jyk has what I needed, Thanks a lot! I'll test that equation in Flash (I find it easier for testing simple things), and if it works I've got everything I need to finish my simple little engine and start programming my GAME. Thanks again!

Also, benishor, thats a nice article and I'll probibly end up using it soon.
*puts in 'useful' folder*
[removed] sorry...

This topic is closed to new replies.

Advertisement