Slicing a 3d cube-like surface with a plane

조회 수: 4 (최근 30일)
Indulgence
Indulgence 2017년 6월 26일
답변: Joshua 2017년 6월 27일
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