Jump to content
  • Advertisement
Sign in to follow this  
Nanook

distance from a point to plane

This topic is 3476 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

Question: Given the plane normal and a point on the plane(eg. P1), explain the process needed to determine how far another point P3 - with coordinates (r,s,t) - is from the plane. Why is P1 mentioned in this question? isnt it the minimum distance from P3 to the plane they want? Im confused with all this.. anyone care to explain so a dummy can understand? :)

Share this post


Link to post
Share on other sites
Advertisement
http://en.wikipedia.org/wiki/Plane_(mathematics)

In a three-dimensional space, another important way of defining a plane is by specifying a point and a normal vector to the plane.

things like this are easy to find, please do so.

Share this post


Link to post
Share on other sites
A normal just defines which direction a plane is facing. However there are an infinite number of planes facing that same direction. Think of the (interior) walls of your house. All the north walls face the same direction, as do all the south/east/west walls. So how do you narrow down which wall you're talking about when you say "the north-facing wall"? You chose a point, and say that you're interested in the north-facing wall that goes through that point (such as the breaker box). Then you know exactly which wall you're talking about. Point P1 behaves the same way and narrows down the exact plane facing a particular direction.

The math will reveal the same fact, I just wanted to explain it in words :)

Share this post


Link to post
Share on other sites
hmm.. still confused.. am I onto something here?;

n = [a,b,c]
D = |n * P3-P1| / |n|
= |a(x - r) + b(y – s) + c(z – t)| / Sqrt(a² + b² + c²)
= |ax + by + cz – ar – as – ct| / Sqrt(a² + b² + c²)
= |-d – ar – as – ct| / Sqrt(a² + b² + c²)
= |ar + as + ct + d| / Sqrt(a² + b² + c²)

Share this post


Link to post
Share on other sites
That seems right. I usually require normal vectors to have length 1, because it simplifies things so much.

#include <iostream>
#include <cmath>

struct Point {
double x,y,z;

Point(double x, double y, double z) : x(x), y(y), z(z) {
}
};

struct Vector {
double x,y,z;

Vector(double x, double y, double z) : x(x), y(y), z(z) {
}
};

double dot(Vector const &v, Vector const &w) {
return v.x*w.x+v.y*w.y+v.z*w.z;
}

Vector operator-(Point const &p, Point const &q) {
return Vector(p.x-q.x, p.y-q.y, p.z-q.z);
}

// We assume normal is a unit vector
struct Plane {
Point point;
Vector normal;

Plane(Point const &point, Vector const &normal)
: point(point), normal(normal) {
}
};

double distance(Point const &point, Plane const &plane) {
Vector diff = point-plane.point;
return std::fabs(dot(diff, plane.normal));
}

int main() {
Point point(10,0,0);
Plane plane(Point(18,6,0), Vector(.8,.6,0));

std::cout << distance(point, plane) << '\n';
}



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!