필터 지우기
필터 지우기

Defining normal unit vector for arbitrary plane surface in 3D space

조회 수: 7 (최근 30일)
fredo ferdian
fredo ferdian 2017년 5월 11일
답변: Matt J 2023년 7월 17일
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

답변 (2개)

Matt J
Matt J 2017년 5월 11일
편집: Matt J 2017년 5월 12일
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
Diaa
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
Matt J 2021년 6월 25일
A very minor improvement, I would guess, but maybe the profiler would tell you differently.

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2023년 7월 17일

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by