Sign in to follow this  

Does a point lie within a cylinder?

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

It seems such an easy question, but the only answer google came up with for it I couldn't quite understand. How do I detect if a point P is within the volume of a cylinder with endpoints A and B (all in R^3) and a given radius at each endpoint?

Share this post


Link to post
Share on other sites
Find the closest point Q on the line AB to P. First you check if the closest point on the line is outside the interval [A, B] on the line; if so, it's outside the cylinder. If it's inside the interval, then you check if the distance from Q to P exceeds the radius of the cylinder, it's outside. Otherwise, it's inside the cylinder. In pseudocode:


public bool PointInCylinder(Point A, Point B, double r, Point P)
{
bool result = false;

Line L = new Line(A, B);
Point Q = L.GetClosestPoint(P);

if (Q.IsBetween(A, B) && Distance(P, Q) < r)
{
result = true;
}

return result;
}

Share this post


Link to post
Share on other sites
Say P1 and P2 are the centers of the "caps" and P is the point of interest. Then (P2-P1)/||P2-P1|| is a unit vector in the direction of P1 to P2, call it U, where ||v|| is the magnitude of vector v. So ||U x (P-P1)|| is the distance of P from the axis of rotation, call it D, where x is the vector cross product. Further P1 + (U.(P-P1))*U is the closest point on the axis of rotation to P, call it CP. So if CP lies between P1 and P2 and D is less than the radius of the cylindar then the point lies in the cylindar.

Been awhile so might be a mistake or two, but the general approach is correct. Basically you are just checking that the point lies between two planes and is within a certain distance of a line.

Share this post


Link to post
Share on other sites

This topic is 4484 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this