Map 3D to 2D

Dear all,

I have an issue. Please help me if you know about it. I would like to build polygons in 2D. the polygons will contain the part of chart that we can see. for example in the image bellow I need to build four polygons correspond to four areas that i marked in red

so what exactly is your issue? What have you done so far?

my Issue is how build those polygon from the part of 3D that we can see

If I understand you correctly, you’ll probably need some kind of tesselator.

Computing those polygons can be broken down in a few steps:

  1. Compute the outline of an object. Your objects - at least in your examples - are boxes. A box is convex, so computing its outline comes down to:
    i. transform all vertices (8) to screen coordinates
    ii. compute frontfacing/backfacing property of all faces (6). this can be done by either applying the winding rule to all vertice of each face, or by the sign of the z-component of the eye-space face normal.
    iii. each edge (12) between two faces with different front-/backfacing property is part of the outline.

  2. Solving overlapping object polygons. The outlines for the individual boxes will most likely overlap (by their neighbors in the first example and by the coordinate axis in both examples).
    In order to correctly remove overlapping areas, you need depth information (which polygon is in front). Your examples imply two helpful properties: 1. the boxes don’t intersect and 2. the boxes are separated by a single axis.
    So you can do something like transforming the x-axis (of your chart) to eye-space, so the sign of it’s z-component tells you, whether your boxes are sorted ascending or descending according to their position on the charts x-axis.
    All that is left is computing pairwise the overlapping area of the box-outlines, and remove the overlapping area from the not-in-front outline.

What i have left out so far is the computation of the outline of the coordinate system, which can occlude the boxes as well (should be straight forward), and possibly clipping computed polygons to the viewport.

I’m curious, what do you need those polygons for ?

Thanks for your help. I need those polygons for supporting area mapping on web

There is another constraint i overlooked at first: the decision which polygon is in front is only determinable by the charts x-axis, if you use a parallel projection matrix.
A perspective projection, looking perpendicular at one box, can lead to this box overlapping its neighbors on both sides (if the eye point is close enough and/or the field-of-view angle is wide enough), and will cause the boxes to its left to have the opposing overlapping order (ascending vs. descending) than those to its right side.

Two additional constraints might help to solve even this situation: 1. your boxes don’t intersect and 2. the front sides of all boxes lie in one plane.
As long as your viewing direction is a the front and from above (first example) all occlusions will be the front or top side of one box in front of the side (left/right) of a neighboring box.
So if you compute an additional flag for each outline segment, whether it’s a front/top side edge, you can tell by those flags which polygon segment lies in front for every intersection.

If viewed from below (second example), this changes to front or bottom side of one box in front of a neighboring boxes side, but the bottom side will most likely be occluded by your coordinate system.

This is getting increasingly complicated, so simpler ideas are welcome :wink:

I did this issues according to your suggestion and it works well. now I am working for removing the overlap that is made by walls from those polygons. Please tell me if you know a good algorithm for excluding a polygon from a polygon. Thank you very much