# [nevermind] sorry...

This topic is 4710 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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]

##### Share on other sites
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.

##### Share on other sites
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 )

##### Share on other sites
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.]

##### Share on other sites
jyg mate, he was actually asking around about the dot() function itself.

Christopher, you would better take a look here

##### Share on other sites
Quote:
 Original post by benishorjyg 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?

##### Share on other sites
You are probably right. I figured that he would know how to use the dotproduct :)

##### Share on other sites
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*

##### Share on other sites
[removed] sorry...

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013547
×