Distance between 2 surfaces along surface normal direction
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello. I have 2 surfaces and I would like to calculate the distance between them along surface normal. I created an example below that illustrates what I am trying to do. It shows 2 surfaces that contain the localized surface normal directions as red lines for each surface. This example uses spheres, but in general the surfaces I would like to evaluate not easily described in functional form. For each of these surface points I would like to calculate the distance along it's surface normal (red line) until it intersects with the other surface. If it does not intersect with the other surface along this direction I would like to report a NaN.
The other section in the Matlab code below isan attempt to see if I understand the surfnorm output correctly. I was trying to derive a line emitting from the 1st surface that is normal and passes through the 2nd surface. The distance for this blue line should be However, I don't think the red and blue lines overlap, so I am not sure if my understanding is correct?
The final output should be 2 sets of distances, since each surface will have a different normal direction and will intersect with the other surface differently. Any suggestions on how I can try to derive these distances for each surface would be greatly appreciated. I have the optimization and curve fitting toolboxes if those functions would help solve this problem. Thank you.
%%Derive distance between 2 surfaces along the surface normal
%create a unit sphere for testing purposes
[XSphere1,YSphere1,ZSphere1] = sphere;
%specify the shift and scale paramters for the 2nd sphere
XShift = 1.5;
YShift = -1.5;
ZShift = 0.5;
XScale = 0.7;
YScale = 1.4;
ZScale = 1;
%scale and shift another sphere
XSphere2 = XSphere1*XScale + XShift;
YSphere2 = YSphere1*YScale + YShift ;
ZSphere2 = ZSphere1*ZScale + ZShift;
%create plots to ensure it makes sense and to visulize the surface normals
figure, surfnorm(XSphere1, YSphere1, ZSphere1)
hold on
surfnorm(XSphere2, YSphere2, ZSphere2)
%%Use the derived scaled surface normal data to show intersection
%not sure if I am intepreting the output from the surfnorm function
%correctly
[Xnorm1, Ynorm1, Znorm1] = surfnorm(XSphere1, YSphere1, ZSphere1);
[Xnorm2, Ynorm2, Znorm2] = surfnorm(XSphere2, YSphere2, ZSphere2);
%scale the normalized normal vector
V2x = Xnorm1*5;
V2y = Ynorm1*5;
V2z = Znorm1*5;
V2x2 = Xnorm1*1;
V2y2 = Ynorm1*1;
V2z2 = Znorm1*1;
%for testing one of the points on the first surface
TestPoint = 180;
%plot one of the surface normals to verify that it makes sense; It looks
%like the red line does not overlap with blue line. Am I using the
%surfnorm output correctly?
figure, plot3([XSphere1(TestPoint), XSphere1(TestPoint) + Xnorm1(TestPoint), V2x(TestPoint), V2x2(TestPoint)],...
[YSphere1(TestPoint), YSphere1(TestPoint) + Ynorm1(TestPoint), V2y(TestPoint), V2y2(TestPoint)],...
[ZSphere1(TestPoint), ZSphere1(TestPoint) + Znorm1(TestPoint), V2z(TestPoint), V2z2(TestPoint)])
hold on
surfnorm(XSphere1, YSphere1, ZSphere1)
surf(XSphere2, YSphere2, ZSphere2)
0 Kommentare
Antworten (1)
Alan Weiss
am 16 Aug. 2017
You could just perform a constrained minimization. Have one endpoint constrained to be in one region, the other endpoint on the other region, and when you get a minimum length of the line between the two points, the line will be normal to the constraining surfaces.
Then again, you need fmincon from Optimization Toolbox™ for this minimization.
Alan Weiss
MATLAB mathematical toolbox documentation
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!