Since SVG does not directly support hyperbolic segments, our goal is to generate an SVG scratch path using cubic Bézier curves.
- Height Value Calculation
The height of each point is determined by the pixel value from thedepthImage
and subtracting a baseline heightzeroHeight
.
- Curvature
Curvature is mapped by translating the height value to the image width. Points with a height greater than zero will produce an upward curve, while points with a negative height will curve downward. The formula for curvature is:
- Offset
Since cubic functions do not pass through the origin at the vertex, we substitute ( t = 0.5 ) into the following equation to obtain an offset:
- Original Function
- After Compensation
We use a cubic Bézier curve to define the path, which consists of a start point, an endpoint, and two control points.
- Origin (Compensation)
- Start and End Points
- Control Points
The mathematical equation for a cubic Bézier curve is:
- ( t ) is the parameter on the curve, where ( t ) ranges from 0 to 1.
- When ( t = 0 ), the point is at the start point ( P_0 ).
- When ( t = 1 ), the point is at the endpoint ( P_3 ).
- The control points ( P_1 ) and ( P_2 ) determine the shape and curvature of the curve.
For each point, a cubic Bézier curve is generated and added to the SVG path:
-
M (Move To): Move to the start point
$( P_0 )$ -
C (Cubic Bézier Curve): Define control points and endpoint
$( P_1, P_2, P_3 )$