1

I wish to fill all points on a plane defined by three points such that:

  • All points' coordinates are integers, i.e, there are no points with decimal coordinates.
  • All points on such plane are not outside the boundaries formed by the three points which define said plane

For example, given the plane P defined by the points A(3, 0, 0), B(0, 3, 0) and C(0, 0, 3):

  • The point D(1, 1, 1) satisfies this condition
  • The point E(6, 3, -6) does not satisfy this condition because it is on the plane but outside the boundaries
  • The point F(4, 1, 3) does not satisfy this condition because it is not on the plane

I've tried applying Bresenham's 3d line algorithm and extend it to plane drawing but I can't figure it out.

Alex
  • 31
  • 4
  • 1
    Smells like an NP-hard problem. You need to find all convex combinations of `A,B,C` with integral coordinates. A naive branch-and-bound idea: Take the enclosing box with axis-parallel sides defined by the points `R_min` having the minimum coordinate of `A,B,C` in each dimension and `R_max` having the respective maximum (in the example: `R_min=(0,0,0), R_max=(3,3,3)`). The box contains all solutions. Recursively partition the box into an octree along integer coordinates. ... – collapsar Apr 06 '20 at 13:34
  • ... Boxes having all vertices on the same side of the plane defined by `A,B,C` (see [this SO question](https://stackoverflow.com/questions/15688232/check-which-side-of-a-plane-points-are-on) on how to compute the side for a single point) cannot contain a solution point, terminate the recursion in the respective branch upon detection. – collapsar Apr 06 '20 at 13:34
  • @collapsar: NP-hard in terms of what ?? Exhaustive search takes an effort proportional to the area of triangle, which is O(N²) where N is the length of the sides. –  Apr 21 '20 at 21:12
  • @YvesDaoust Yes, Hekto's answer settled that the guess was wrong. – collapsar Apr 21 '20 at 22:04

2 Answers2

0

At first let's find minimal ZMin and maximal ZMax values of the z-coordinate of three vertices, defining your 3D triangle. Now imagine a number of planes, parallel to the xy-plane, and having the integer z-coordinate in the range (ZMin, ZMax). Each of these planes intersects with your triangle, giving a line segment - find all the end points of these segments. If to assume that all the coordinates of triangle vertices are integer numbers (according to your example), then all these line segments will have end points with rational coordinates.

So, you have reduced the original problem of rasterization of the 3D triangle to a finite number of subproblems, and each of them looks like this: given a line segment on the plane with rational end points, find all the points with integer coordinates, lying on this segment. Fortunately this subproblem can be solved efficiently - for example, please see here.

HEKTO
  • 3,876
  • 2
  • 24
  • 45
0

Scan filling solution:

Project the triangle to XY and scan fill it (consider all integer ordinates Y between Ymin and Ymax and for each Y find the Xmin and Xmax by intersection with the sides; take all intermediary X's).

Then check if the corresponding Z is an integer (the equation of the plane is a.X + b.Y + c.Z + d = 0).

The amount of work is proportional to the projected area of the triangle.

You can speedup the process a little by noting that for a constant Y, you only use the solutions of the diophantine equation a.X + c.Z = - d - b.Y. This equation only has solutions if gcd(a, c) divides d + b.Y and this restricts the possible Y.


In your case, the plane is X + Y + Z = 3 and the projected triangle (0, 0), (3, 0), (0, 3).

By filling, there are ten grid points, of which the three corners, six points on the edges and another inside. For all these points, Z is an integer. (The acceleration techniques do not apply here.)

(0, 0, 3), (1, 0, 2), (2, 0, 1), (3, 0, 0), 
(0, 1, 2), (1, 1, 1), (2, 1, 0),
(0, 2, 1), (1, 2, 0), 
(0, 3, 0).