フィルターのクリア

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
  1 件のコメント
yashodeep
yashodeep 2023 年 7 月 17 日
%program to find unit norma to the surface

サインインしてコメントする。

回答 (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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by