# convert 3D model to 2D slices

This topic is 3960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hello guys... i want to convert my 3D model into 2D slices...means for marching cube algorithm...i need to convert 3D model into 2D model(no of 2D slices)... how can i do this... plz help me...

##### Share on other sites
If I understood you correctly, just compute the intersection between the 'slice plane' and each triangle of the mesh. If the triangle intersects the plane, get the intersection points(one point if the one vertex of the triangle touches the plane, two points(one segment) if the triangle crosses the plane, no points if the triangle does not cross the plane or if the triangle is parallel to the plane, get each edge of the triangle) and build the edges of the 2D slice from them . . . well, not sure if this helps nor if its the best approach, I'm just trying to clear things up, but anyway HTH :)

##### Share on other sites
from where can i get this kind of information....means sample codes related to this topic......
or
any other material....

##### Share on other sites
This gives you a wireframe representation

for each polygon P    for each line L in polygon P        if line intersects polygon            if line (L-1 wrapped to last polygon if L == 0) also hits polygon                draw a line between those intersection points            else                draw a point for the intersection point.            end if        end if    nextnext

this fails in the (possibly?) rare case that all lines on the polygon intersect the plane, such as when the polygon is on the same plane as the slice.

I have code for triangles and planes to collide with rays, lines and line segments and return the collision points. If you want to learn this stuff yourself, start with vector maths, then learn to collide lines with planes. rays and line segments are a subset of lines. You will need to be able to do the following functions:

bool line_vs_plane(line * l, g_vector t1,                   plane * p, g_vector t2,                   g_vector & contact_point);//line is assumed to be infinate in both directionsbool ray_vs_plane(line * l, g_vector t1,                  plane * p, g_vector t2,                  g_vector & contact_point);//ray is assumed to be infinate in + direction away from its originbool point_inside_triangle(g_vector pt, g_vector t1,                           triangle * p, g_vector t2);//using the angle testbool line_vs_triangle(line * l, g_vector t1,                      triangle * t, g_vector t2,                      g_vector & contact_point);//infinite in all directionsbool ray_vs_triangle(line * l, g_vector t1,                      triangle * t, g_vector t2,                      g_vector & contact_point);//infinate along its direction vectorbool lineseg_vs_triangle(line * l, g_vector t1,                         triangle * t, g_vector t2,                         g_vector & contact_point);//between two pointsbool triangle_vs_triangle(triangle * p1, g_vector t1,                          triangle * p2, g_vector t2,                          g_vector & contact_point);//uses up to six edge tests, returns true on the first contactbool line_vs_aabb(line * l, g_vector t1,                  aabb * b, g_vector t2,                  float & contact_point);bool line_vs_mesh(line * l, g_vector t1,                  collision_mesh * m, g_vector t2,                  g_vector & contact_point);//brute force method; recursively test every polygon until an intersection occurs

from there, testing compound shapes such as a triangle simply involves a series of lower level collision tests, such as line vs plane followed by point vs polygon.

##### Share on other sites
You could possibly try using rendering your 3d model using your favourite API and using orthogonal projection and a combination of z testing and clipping to get the 2d render at different projection along the slice axis.

Might be an easier way to do it then doing intersection tests.

##### Share on other sites
my model is a triangular mesh......
which one from above function is useful for me......

line vs plane
or
line vs triangle

and is there any other method to marching cube......just first convert triangular data to cube data.....then draw mesh of voxels...

##### Share on other sites
I dont understand you clearly what you wana do but heres possibility that this libbrary will help you: http://www.geuz.org/gl2ps/

It has export to pdf, svg and postscript. You can use output files to coopeate with your application. Just parse it.

Also usefull can be svgl lib to draw svg in opengl.

1. 1
2. 2
3. 3
Rutin
25
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633649
• Total Posts
3013117
×