Slicing a 3d cube-like surface with a plane

5 次查看(过去 30 天)
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 个评论
KSSV
KSSV 2017-6-27
Attach the data with your triangle vertices, so that we can try.
Walter Roberson
Walter Roberson 2017-6-27
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() ?

请先登录,再进行评论。

回答(1 个)

Joshua
Joshua 2017-6-27
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.

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by