How to tessellate bezier triangles?

I am concerned about the quadratic bezier triangles that I am trying to use to render them.

I managed to realize this by dividing the triangle recursively, as described on the wikipedia page. Although I would like to get more accuracy for the unit. The problem is that I will either get too few units, or too many, because the number of surfaces doubles at each iteration of this algorithm.

In particular, I will need an adaptive tessellation algorithm that allows me to determine the number of segments at the edges. I'm not sure if I can get this, so I would also like to hear about standardized tessellation methods.

The most difficult problem. I have problems calculating the normals for a point on the bezier surface, which I'm not sure if I need, but tried to solve the problem.

+3
source share
1 answer

Adaptive Tessellation. There are many algorithms. But here is one:

def line_angle((x0,y0),(x1,y1)):
    return atan2(y1-y0,x1-x0)

def adaptive_bezier(p0,p1,p2,lev=32):
    p01 = midpoint(p0,p1)
    p12 = midpoint(p1,p2)
    m = midpoint(p01, p12)
    da = abs(line_angle(p0,p1) - line_angle(p1,p2))
    if da <= max_tolerance or lev <= 0:
        yield m
    else:
        for p in adaptive_bezier(p0,p01,m,lev-1): yield p
        for p in adaptive_bezier(m,p12,p2,lev-1): yield p

Complications arise for the tessellation of triangles in this way. You need to control the adaptive tessellator algorithm in accordance with the angles of the extreme beziers. There are three unique ways how your triangle can split when tesselating.

 2 edges      one edge     3 edges    
--------     ---------    --------
\  ...//     \   |   /    \ /  \ /
 \/___/       \  |  /      \____/
  \  /         \ | /        \  /
   \/           \|/          \/

Define tessellation results for these patterns and you are provided. Only single-edge tessellation is described in the Wikipedia article.

Two other tessellation results can be obtained by studying the case of one edge partition.

"2 " , , .

"3 " - , . , "2 " -case . , :

--------      /\
\      /     /  \
 \____/     -____-
  \  /       \  /
   \/         \/
+1

Source: https://habr.com/ru/post/1720065/


All Articles