# Peel End Corners

A similar technique has already been implemented in the early versions, but due to completely changed design we come back to it in this post.

Peel rule produces and extruded shape along the normal of each segment. It means this shape starts and ends at right angle to the appropriate segment. This is find when for instance when extruding a small section in the middle of the edge, however for peel ranges at the edge boundary this may produce substrate shape with sharp angles:

For sharp-enough angles (e.g. under 60 degrees) it makes sense to merge the extruded shapes with the neighbouring edges. Epsilon areas are added at the merge boundary regions to avoid erroneous shapes resulting from numerical errors:

In fact we just take two corners at the boundaries and unite them together with the extruded shape:

Given two geometrically consecutive edges e1 and e2 where e1.second == e2.first, we have two options for creating a boundary corner. For the front or start of the range e2 is used for extrusion and other way round for the back. The corner is simply triangle spanned by vector a – normal direction, and b – projection of a to the adjacent edge.

#### Projection of a to b

Let us consider the front case. Since a and e1 is known we compute b:

• from definition of dot product
(|a||e1|cos),cos = dot(a,e1)/(|a||e1|),
• 1/cos = |a||e1|/dot(a,e1)
• By looking at right-angled triangl, length of b is
|b| = |a| (|a||e1|/dot(a,e1)
• So b is unit(b)*|b| and since unit(b) = unit(e1) as both point in the same direction
b = unit(e1)|b| = unit(e1)|e1| (|a|^2) /dot(a, e1)
b = e1 * (|a|^2) /dot(a, e1)

#### Epsilon Extension

In the context of triangles endpoints corresponding to a an be span a line segment s = (o + a, o + b), where o is local origin: e1.second (or e2.first). s is extended in both directions by epsilon: s’. Boundary corner is now (o, s’.first, s’.second) for front and (o, s’.second, s’.first) for back cases.

#### Determination of Angle Sharpness

An angle formed between two edges e1 and e2 determines the need for boundary corners. Dot and Cross products informing about cos and sin respectively allow us to determine the quadrant of the angle when we consider e2 as fixed and e1 resolving around it.

We want the forth quadrant, when cos > 0 and sin < 0. When

• cos <= 0, angle between adjacent edges is sharp already or a right one which means that an extruded shape at boundary will touch the adjacent edges anyway.
• sin >= 0, we have a concave (greater than 180 degrees) for flat (180 degrees) angle. If we want to limit sharpness to 60 degrees the cross product is expteded to be within the range [-1, -sin(60)]

#### Direction of Indexing

When indexing is negative we need to:

1. Swap e1 and e2, because geometrically e2 preceeds e1, and
2. Change front and back flag, since the edges are swapped we expect front where otherwise back would go.