You can look at this as height field on triangle B=[(0,0),(0,1),(1,0)]
.
Since plane is defined as heights on corners of B
, height of plane on B
inner point can be calculated with barycentric coordinates. With given:
- plane with heights
(a,b,c)
on corners of B
- point
P
in B
with barycentric coordinates (x,y,z) [x+y+z=1, x,y,z>=0]
,
height of plane on point P
is x*a + y*b + z*c
.
Natural barycentric coordinates for point P=(x,y)
in B
is (x,y,1-x-y)
.
With this it is easy to calculate intersection line of 2 planes, (a1,b1,c1)
and (a2,b2,c2)
, in barycentric coordinates.
Just equalize where 2 planes have same height
x*a1 + y*b1 + (1-x-y)*c1 = x*a2 + y*b2 + (1-x-y)*c2
=>
x*(a1-c1-(a2-c2)) + y*(b1-c1-(b2-c2)) + c1-c2 = 0
With 0 <= x,y <= 1
and x+y <= 1
, 2 planes this is equation of 2 planes intersection line in B
.
I think that there are 2 approaches that can be used for creation of resulting height field (top most layer):
Iterative adding new triangle
To support it, it is needed to have structure that is
partition of triangle B
into polygons. Polygon is region of triangle where one plane is the highest. Since we are dealing with planes, polygons will be convex and one plane can produce at most one polygon.
Adding new triangle and calculation of intersections with existing height field polygons will produce
new polygon (intersection lines and border of B
).
This new polygon is added to height field. If existing polygon is intersected than part is removed. If existing polygon is overlapped than polygon is removed.
Propagation of intersection front line
- Start from one corner and take plane that is the heighest on it (e.g. plane wiht max(a_i)). Set front line to that corner.
- Find planes that intersect starting plane with intersection lines nearest to front. Move front to these intersection lines.
- Take one (any) plane that is on front line and make intersection with not processed planes with intersection lines nearest to front. Move front to these intersection lines.
Repeat 3. until front line covers triangle B
.
I prefer second algorithm.