Slicing a 3d cube-like surface with a plane
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a 3D surface in Cartesian coordinate system which I plot using surf(x,y,z). It is a cube-like surface, which is centred on 0,0,0. I would like to slice it with a plane, which would cross the three most distant corners of a cube. Please see the picture attached. Then I would like to plot the sliced contour.
2 Kommentare
Walter Roberson
am 27 Jun. 2017
It looks to me as if for any given x, y pair that there could be multiple z. I do not see how you could draw that using surf(x,y,z) -- at least not without inserting NaN into the coordinates. Is it definitely surf() you are using, rather than creating a patch() ?
Antworten (1)
Joshua
am 27 Jun. 2017
Assuming that you have the cube shaped object as a list of coordinates, you could define the plane as an equation, and then check the equations result from each coordinate. If it is less than zero, keep the point. If it is greater than zero, delete it.
Let you three points be p1=(x1,y1,z1), p2=(x2,y2,z2), and p3=(x3,y3,z3), and let xC=(x,y,z) be a random coordinate point. You can then define vectors v1=p1-p2 and v2=p1-p3. Cross multiply these to get a vector normal to the plane n=(a,b,c)=(v1)X(v2). The equation of your plane is then n*(xC-p1)=a(x-x1)+b(y-y1)+c(z-z1)=0. Test a point using:
if(a(x-x1)+b(y-y1)+c(z-z1) > 0)
% delete point
else
% do nothing, keep point
end
Here is a reference link. Depending on which points you choose to be p1, p2, and p3, you might have to multiply the equation by -1 to make it work, but you would see if you need to do that when you plot the results.
0 Kommentare
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!