Defining normal unit vector for arbitrary plane surface in 3D space
이전 댓글 표시
Dear All,
I'm trying to find unit vector which pointing perpendicularly outward from arbitrary shape of panel in 3D space. I found from other similar question, that it can be done by calculating the cross product of the points in the panel. I did the same thing, but there is some error which I can't really understand. A tried to do it by using these three methods below:
if true
%
A = [-225.0000 2.7555e-14 0];
B = [-225.0000 2.7404e-14 -2.8802e-15];
C = [-223.6800 24.3270 0];
D = [-223.6800 24.1940 -2.5428];
center = (A+B+C+D)/4
% Method1: Calculating unit vector by seeing the coordinate of center point of the panel as a vector from axis of origin then normalized it
UnitVector1=center/norm(center)
CheckA1=(UnitVector1(1,1)^2+UnitVector1(1,2)^2+UnitVector1(1,3)^2)^0.5
CheckA2=cross(center,UnitVector1)
max(abs(CheckA2))
% Method2: Obtaining unit vector by calculating cross product of the vectors at panel's corner point
UnitVector2=cross((D-A),(B-A));
UnitVector2=UnitVector2/norm(UnitVector2)
CheckB1=(UnitVector2(1,1)^2+UnitVector2(1,2)^2+UnitVector2(1,3)^2)^0.5
CheckB2=cross(center,UnitVector2)
max(abs(CheckB2))
% Method3: Obtaining unit vector by calculating cross product of the panel's center point
Point1=(A+B)/2;
Point2=(B+C)/2;
UnitVector3=cross((Point1-center),(Point2-center));
UnitVector3=UnitVector3/norm(UnitVector3)
CheckC1=(UnitVector3(1,1)^2+UnitVector3(1,2)^2+UnitVector3(1,3)^2)^0.5
CheckC2=cross(center,UnitVector3)
max(abs(CheckC2))
end
These panel coordinates are taken from sphere-shaped 3D bodies. It means that the center point of the panel itself, when being normalized, is already become the unit vector which pointing outward of the panel (method 1). when I do cross product between the obtained unit vector and the center coordinate, the result is going to be zero (achieved with first method with error precision 10^-16) because there is no area generated between those vectors. But, since I'm dealing not only with sphere-shaped object, I need to find another way which more applicable for other case (method 2 and 3). But apparently, the resulting cross product between obtained unit vector and the center point coordinates is not zero, which means it's not perfectly perpendicuar outward the panel.
Any idea to improve/solve this issue will be highly appreciated.
Regards,
Fredo Ferdian
댓글 수: 1
yashodeep
2023년 7월 17일
%program to find unit norma to the surface
답변 (2개)
Here's a general way to fit a plane normal to any number of points,
V=[A;B;C;D];
V=V-mean(V); %assumes R2016b or later, otherwise use bsxfun()
[U,S,W]=svd(V,0);
normal=W(:,end)
댓글 수: 11
fredo ferdian
2017년 5월 11일
Matt J
2017년 5월 12일
I've modified my code. It should work now.
fredo ferdian
2017년 5월 12일
LC
2020년 10월 3일
Matt J,
Is the normal always pointing outward?
Matt J
2020년 10월 3일
@LC, the only guarantee is that the normal is perpendicular to the fitted plane. The code doesn't know which of the two possible directions you consider to be "outward".
Diaa
2021년 6월 22일
Is it possible to find from your code the basis vectors of the plane passing through the points without using the function pca?
Diaa
2021년 6월 22일
If you don't mind, would you please help me know how to calculate the direction cosines of the output normal vector?
Thanks in advance.
Diaa
2021년 6월 25일
In terms of perfromance, is it better to make it
V = V-mean(V);
[U,S,W] = svd(V,0);
or in one step using
[U,S,W] = svd(V-mean(V),0);
I am talking about tens of this operation, so is nesting the calculations always a good idea in favor of performance instead of overwriting the existent variables (e.g. V here)?
Matt J
2021년 6월 25일
A very minor improvement, I would guess, but maybe the profiler would tell you differently.
Matt J
2023년 7월 17일
0 개 추천
Use planarFit() in this FEX download,
카테고리
도움말 센터 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!