Jump to content
  • Advertisement
Sign in to follow this  
too_many_stars

plane point distance help

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello Everyone,

I am having an issue with a point plane distances, and was wondering if anyone could help me.

To start, a plane is defined by a unit normal, and a distance from the origin Plane(Vec2,float) while a point is simply a point in space Vec2.

To get the distance between a point and a plane, usually something like this is done:

float distance = dot( plane_normal , point ) + plane_distance_from_origin. So far so good. The issue lies with the following example. Say we have:

This also assumes that top left is the origin.

Plane plane1(Vec2(1,0),0)

Plane plane2(Vec2(1,0),50)

Plane plane3(Vec2(-1,0),350)

Plane plane4(Vec2(-1,0),400)

and a Point at (200,0)

The following would be the distances

point to plane1 = dot( Vec2(1,0) , Vec2(200,0)) + 0 = 200 //Correct distance

point to plane2 = dot( Vec2(1,0) , Vec2(200,0)) + 50 = 250 //WRONG!! incorrect distance. S/B 150

point to plane3 = dot( Vec2(-1,0), Vec2(200,0)) + 350 = -200 + 350 = 150 //Correct distance

point to plane4 = dot( Vec2(-1,0), Vec2(200,0)) + 400 = -200 + 400 = 200 //Correct distance

 

My issue is with "point to plane2" distance. I am not sure how to deal with this problem. Could someone please suggest a solution, or give me a source.

Thank you very much.

 

Mike

Share this post


Link to post
Share on other sites
Advertisement

Your equation for the distance between the plane and point is incorrect.  Should be:

dist = dot(n, p) - D

where:

p = point

n = plane normal

D = dist from origin to plane

Share this post


Link to post
Share on other sites

I'd normally do

distance = dot(normal, point - pointOnPlane)

I don't see how you can use distance from origin only, how do you know if the plane lies in the negative or positive x-axis?

Share this post


Link to post
Share on other sites
4 hours ago, Syntac_ said:

I'd normally do

distance = dot(normal, point - pointOnPlane)

I don't see how you can use distance from origin only, how do you know if the plane lies in the negative or positive x-axis?

The normal tells you where the plane is.  For example, n = (1,0,0) with some D > 0 means the plane is D units in the +x direction.  (-1,0,0) also with D means it's D units in -x direction.

If D = 0, then n = (1,0,0) is the same plane as n = (-1,0,0) which intersects the origin.

Share this post


Link to post
Share on other sites
6 hours ago, Syntac_ said:

I'd normally do

distance = dot(normal, point - pointOnPlane)

I don't see how you can use distance from origin only, how do you know if the plane lies in the negative or positive x-axis?

this is a pretty common question. One way to understand the two forms of the plane equation is with a little vector algebra.

ax + by - c = 0
ax + by = c
ax + by = dot({a, b}, {x, y})
ax + by = dot(normal, point_on_plane)

Solving for distance to plane is basically the first line with a non-zero on the right-hand side:

ax + by - c = distance
=>
dot(normal, point_on_plane) - c = distance

But sometimes we have yet to solve for c, or we are given c in the form of another point. Lets just call it point, like in your example:

dot(normal, point_on_plane) - dot(normal, point) = distance
=>
dot(normal, point_on_plane - point) = distance

c is known as "distance to the origin along the direction of the plane normal". It's apart of the plane equation and can be found with the dot product. It's important to understand all this stuff for games programming.

Personally I define planes like so:

struct Plane
{
	Vec2 normal;
	float distance;
};

float DistToPlane( Plane plane, Vec2 p )
{
	return dot( plane.normal, p ) - d;
}

 

Edited by Randy Gaul

Share this post


Link to post
Share on other sites
2 hours ago, 0r0d said:

The normal tells you where the plane is.  For example, n = (1,0,0) with some D > 0 means the plane is D units in the +x direction.  (-1,0,0) also with D means it's D units in -x direction.

If D = 0, then n = (1,0,0) is the same plane as n = (-1,0,0) which intersects the origin.

Of course, you are correct, I'm having a memory lapse.

Share this post


Link to post
Share on other sites

Thanks for the replies guys. But I must be missing something.

Given the correct formula that was quoted:

dist = dot( plane_normal , point ) - plane_distance

As opposed to the one I used:

dist = dot( plane_normal , point ) + plane_distance

and the same planes I defined above, we get the following answers.

Plane plane1(Vec2(1,0),0)

Plane plane2(Vec2(1,0),50)

Plane plane3(Vec2(-1,0),350)

Plane plane4(Vec2(-1,0),400)

and a Point at (200,0)

The following would be the distances

point to plane1 = dot( Vec2(1,0) , Vec2(200,0)) - 0 = 200 //Correct distance

point to plane2 = dot( Vec2(1,0) , Vec2(200,0)) - 50 = 150 //Correct distance

point to plane3 = dot( Vec2(-1,0), Vec2(200,0)) - 350 = -200 - 350 = -550//Wrong distance //s/b 150

point to plane4 = dot( Vec2(-1,0), Vec2(200,0)) - 400 = -200 - 400 = -600 //Wrong distance s/b 200

Whether you add or subtract the plane distance from the dot product, you will still get the wrong numbers (as far as I can tell)

The only way I can think of getting around this is using negative plane distances in some cases, which is not very intuitive.

 

Thanks,

 

Mike

Share this post


Link to post
Share on other sites
2 hours ago, too_many_stars said:

Thanks for the replies guys. But I must be missing something.

Given the correct formula that was quoted:

dist = dot( plane_normal , point ) - plane_distance

As opposed to the one I used:

dist = dot( plane_normal , point ) + plane_distance

and the same planes I defined above, we get the following answers.

Plane plane1(Vec2(1,0),0)

Plane plane2(Vec2(1,0),50)

Plane plane3(Vec2(-1,0),350)

Plane plane4(Vec2(-1,0),400)

and a Point at (200,0)

The following would be the distances

point to plane1 = dot( Vec2(1,0) , Vec2(200,0)) - 0 = 200 //Correct distance

point to plane2 = dot( Vec2(1,0) , Vec2(200,0)) - 50 = 150 //Correct distance

point to plane3 = dot( Vec2(-1,0), Vec2(200,0)) - 350 = -200 - 350 = -550//Wrong distance //s/b 150

point to plane4 = dot( Vec2(-1,0), Vec2(200,0)) - 400 = -200 - 400 = -600 //Wrong distance s/b 200

Whether you add or subtract the plane distance from the dot product, you will still get the wrong numbers (as far as I can tell)

The only way I can think of getting around this is using negative plane distances in some cases, which is not very intuitive.

 

Thanks,

 

Mike

No, your expected distances are incorrect. A plane at -350 parallel to the y axis and a point at 200 are 550 units apart, not 150.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!