Cross section of 3d shape

edited July 2015 in How To...

I'm trying to get a cross section of a 3d shape from any given Z position. My current sketch only shows the top and bottom plane.

void setup() {
  size(400, 400, P3D);
  ortho();
}

void draw() {
  background(0);
  translate(200, 200, 145);
  box(200);
  ortho(0, width, 0, height, mouseY, mouseY + 1);
}

What would be the correct way to do this?

Answers

  • The problem with this approach seems to be that the box isn't filled with anything and so only the top and bottom planes become visible. I don't know if it's possible to fill it. Maybe someone knows a better way to get a cross section.

  • edited July 2015

    As you have discovered, the box is empty. There is no easy way to do this.

    But why are you trying to do this? Why bother getting a cross-section of an empty box?

    Now if you had a 3D data set... Now that would be more interesting...

  • Now if you had a 3D data set...

    I chose the box to keep my example simple and easy to try out. The goal is to be able to load a .obj file and get a cross-section of that.

  • edited July 2015

    Again, there is no easy way to do this. The trouble lies in being able to tell if a point is "inside" or "outside" an object. This is incredibly hard to determine.

    For a simple geometric shape, e.g. cubes, cones, spheres, it might be possible to do mathematically. But for a generic object this will be a lot harder (if not impossible).

  • the front clipping plane might be useful for this - move the plane so it slices through the object (or move the object so it straddles the plane).

    z-near here: https://processing.org/reference/perspective_.html

    (i think raw opengl lets you specify general clipping planes, not just front and back)

  • the front clipping plane might be useful for this

    The example I posted in the OP actually uses the clipping planes of ortho()

    The trouble lies in being able to tell if a point is "inside" or "outside" an object.

    I looked into that a little. There seems to be a method with counting intersections of a ray starting at the point I want to check. I don't know how to count these intersections though.

    It doesn't need to be verry fast by the way.

Sign In or Register to comment.