1

I work in isometric. I have a set of polygons that form a specific body. Polygons consist of some points with coordinates x, y, and z, which are in the same plane. Polygons do not intersect each other. When drawing, I want to make sure that the farthest polygons are drawn first, and then the close ones (so that the near polygons seem to overlap the farthest ones). I tried to sort polygons by the arithmetic mean of the sum of their points coordinates, by points the sum of the coordinates of which is the largest of all, and so on. But in certain cases this did not give the desired result. How to determine the order of drawing polygons so that the nearest ones are drawn last?

enter image description here

saastn
  • 5,717
  • 8
  • 47
  • 78
Ivan
  • 21
  • 2
  • 1
    This is not simple because your planes are not paralell to the plane of projection. For each pair of planes A,B you must find its line of intersection and then find which half-of-plane is seen. – Ripi2 Jun 04 '21 at 19:19

1 Answers1

0

It's good news that your polygons are planar and don't intersect each other. This way each polygon is extended between a minimum and maximum depth that could be found by their corners. Using almost all 3D to 2D projection methods (like the one described here), after transforming each point, a 3D point is obtained. The first and second coordinates of these points are used for 2D drawing, and the third coordinate is discarded. These third coordinates indicate the depth of the point and can be used to sort polygons.

When using a Z-buffer is not an option, to manually draw three-dimensional objects, the polygons must be ordered by their maximum depth and then by their minimum depth. But when implementing the sort algorithm, you must take care of the floating point errors. Assume that the minimum and maximum depths of the corners are calculated for each of the polygons. The sort algorithm could be something like this:

for i = 0 to n-2
  for j = i+1 to n-1
    if (p[j].MaxD < p[i].MaxD - eps) or 
       ((abs(p[j].MaxD - p[i].MaxD)<eps) and
        (p[j].MinD < p[i].MinD - eps)) then
        swap(p[i], p[j])
    end if
  end for
end for
        

, where eps is a very small positive value, e.g. 1e-10.

saastn
  • 5,717
  • 8
  • 47
  • 78
  • Sorry, I didn't quite figure out how to calculate the minimum and maximum depths. How to find them knowing the polygon points (x, y ,z coordinates) and the plane equation of the polygon? – Ivan Jun 07 '21 at 09:38
  • @Ivan The depth of a point is not something that can only be calculated based on the coordinates of the point, another important parameter is the position and characteristics of the point of view (the camera). Imagine there is a hypothetical plane in space that is parallel to your monitor screen. To draw a 3D scene, we project all the points on this virtual plane. The depth of a point is the closest distance from that point to this hypothetical plane. – saastn Jun 07 '21 at 10:19
  • @Ivan So to find depth of the point is completely related to the math you are using to transform points from their actual 3D space to the 2D drawing plane. – saastn Jun 07 '21 at 10:21
  • Do I understand correctly that the maximum depth will be the distance from the closest point to the camera? Can the camera be taken as a plane (The plane is given by three points in the case of isometry, for example (x y z order) (1,0,0) (0,1,0) (0,0,1)) that is parallel to the viewer and the task is reduced to finding the distance from points to this plane? And the minimum found distance will be the minimum depth, and the maximum distance will be the maximum depth? – Ivan Jun 07 '21 at 11:36