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!