File Exchange

image thumbnail

dist2plane

version 1.0.0.0 (1.79 KB) by Val Schmidt
A function to calculate the distance from a point to a plane.

3 Downloads

Updated 25 Apr 2012

View License

Given a point in 3D space, and a plane parameterized by its coefficients (C = [a b c] where z = a*x + b*y + c), dist2plane will calculate the distance from the point to the plane along the normal.

Cite As

Val Schmidt (2021). dist2plane (https://www.mathworks.com/matlabcentral/fileexchange/36363-dist2plane), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Ronen Yudzinsky

Jan

I'm used to define a plane as "ax+by+cz+d=0", by the normal and one point or by three points. Can your formula define the XY-, YZ- and XZ-planes?
See http://en.wikipedia.org/wiki/Plane_%28geometry%29

Val Schmidt

Hi Jan,
The plane is defined by the equation:
z = C(1)x + C(2)y + C(3)

Try
x=1:10;
y=1:10;
[xx yy ] = meshgrid(x,y)
C = [1 2 3];
zz = C(1)*xx+C(2)*yy+C(3)
surf(xx,yy,zz,'edgecolor','none')

-Val

PS. You are right about the transposing. Thanks.

Jan

I do not get how to define the plane:
"C: 3x1 plane coeficient vector i.e., zplane = C(1)*x+C(2)+C(3)". Which value of C defines the e.g. Z-plane?
In "sqrt(sum((po-pp)'.^2))" the transposing is inefficient. Better: "sqrt(sum((po-pp).^2, 2))"

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!