Calculating normal on a plane: Can't get proper results
3 次查看(过去 30 天)
显示 更早的评论
I am trying to calculate a normal on a plane using the cross command. When I try to test the result with dot, it seems, the resulting vectors isn't perpendicular to the two vectors I used for cross. What is my problem?
%load data
filename = 'test.xlsx';
sheet = 1;
%x|y|z are vectors, u|v|w is 0|0|0
x = xlsread(filename,sheet,'D1:D10');
y = xlsread(filename,sheet,'E1:E10');
z = xlsread(filename,sheet,'F1:F10');
u = xlsread(filename,sheet,'A1:A10');
v = xlsread(filename,sheet,'B1:B10');
w = xlsread(filename,sheet,'C1:C10');
%get three points from the plane: P1=(0|0|0), P2 and P3
x1fornormal= 0;
y1fornormal= 0;
z1fornormal= 0;
P1fornormal= [x1fornormal y1fornormal z1fornormal];
x2fornormal= x(1,1);
y2fornormal= y(1,1);
z2fornormal= z(1,1);
P2fornormal= [x2fornormal y2fornormal z2fornormal]
x3fornormal= x(2,1);
y3fornormal= y(2,1);
z3fornormal= z(2,1);
P3fornormal= [x3fornormal y3fornormal z3fornormal]
%construction of the normal to the plane
Normal= cross(P2fornormal,P3fornormal)
dot(Normal,P2fornormal)==0 & dot(Normal,P3fornormal)==0
0 个评论
采纳的回答
Roger Stafford
2016-10-31
编辑:Roger Stafford
2016-10-31
You should not be requiring an exact zero for those dot products, since in most circumstances your computations will involve round-off errors. Provide a tolerance for a difference from zero in accordance with the amount of error which you would reasonably expect.
Remember, Matlab’s ‘double’ format has only 53 bits in its significand (mantissa) which is equivalent to about 16 decimal places. Do something like this:
abs(dot(Normal,P2fornormal))<tol & abs(dot(Normal,P3fornormal))<tol
where ‘tol’ is approximately a few ‘eps’ times the product of the magnitudes you expect for ‘Normal’ and ‘P2’ or ‘P3’, the quantity ‘eps’ being 2^(-53),
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!