-
Notifications
You must be signed in to change notification settings - Fork 73
/
getplanefrom3pt.m
27 lines (24 loc) · 759 Bytes
/
getplanefrom3pt.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function [a, b, c, d] = getplanefrom3pt(plane)
%
% [a,b,c,d]=getplanefrom3pt(plane)
%
% define a plane equation ax+by+cz+d=0 from three 3D points
%
% author: Qianqian Fang, <q.fang at neu.edu>
%
% input:
% plane: a 3x3 matrix with each row specifying a 3D point (x,y,z)
%
% output:
% a,b,c,d: the coefficient for plane equation ax+by+cz+d=0
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%
x = plane(:, 1);
y = plane(:, 2);
z = plane(:, 3);
% compute the plane equation a*x + b*y +c*z +d=0
a = y(1) * (z(2) - z(3)) + y(2) * (z(3) - z(1)) + y(3) * (z(1) - z(2));
b = z(1) * (x(2) - x(3)) + z(2) * (x(3) - x(1)) + z(3) * (x(1) - x(2));
c = x(1) * (y(2) - y(3)) + x(2) * (y(3) - y(1)) + x(3) * (y(1) - y(2));
d = -det(plane);