SVG Graphics Geometry
Guide
css-matrix
Guide
css-matrix
  • Part 0. SVG 기초

    • SVG란 무엇인가
    • viewBox와 user space
    • transform attribute와 matrix
    • SVG 문서 구조와 기본 도형
  • Part 1. Path grammar

    • path d 명령어 — M, L, Z
    • H, V — 축 정렬 직선
    • C — cubic Bézier
    • Q — quadratic Bézier
    • S, T — smooth continuation
    • A — elliptical arc
    • path bounding box
  • Part 2. Stroke geometry

    • 점에서 stroke까지의 거리
    • join, cap, miter limit
    • stroke align과 outline 개념
    • miter length 공식
  • Part 3. Fill rules

    • nonzero vs evenodd
    • fill hit testing
  • Part 4. Path sampling

    • flatten tolerance
    • path length
    • point at length와 tangent
  • Part 5. Paint servers

    • linearGradient 좌표
    • clipPath와 mask 개념
  • Part 6. Path editor capstone

    • path handle 모델
    • handle hit testing
    • handle drag로 segment 갱신
    • mini path editor — SVG round-trip
  • Part 7. Fill & winding deep dive

    • winding vs ray casting
    • compound path — 여러 subpath
    • self-intersection
    • path boolean
    • fill vs stroke hit 우선순위
    • scanline parity
  • Part 8. Pattern & gradient

    • radialGradient
    • pattern tile
    • gradientUnits와 spreadMethod
  • Part 9. SVG filter & Figma effects

    • Figma DROP_SHADOW → SVG filter
    • filter chain 개요
    • blur · offset · merge
    • inner shadow
    • layer blur vs background blur
    • Figma effect 매핑표 전체
  • Part 10. Figma ↔ SVG bridge

    • vector network vs path d
    • fill · stroke export
    • boolean operations export
    • mask · clip export
  • Part 11. Icon design

    • pixel grid · optical alignment
    • fill vs stroke icons
    • symbol · sprite · currentColor
    • path simplification
  • Appendix A. SVG in CSS

    • currentColor · CSS theming
    • sprite data URI
    • SVG optimization pipeline
  • Appendix B. Engine extras

    • dash offset animation
    • adaptive flatten
    • arc → cubic 변환
    • multi-subpath editing
  • Part 12. Foundations primer

    • capability map
    • coordinate stack
  • Part 13. Figma ↔ SVG (deep)

    • Figma paint gap map
    • radial · angular gradient export
    • image · pattern fill
    • stroke align export
    • blend mode · layer opacity
  • Part 14. SVG spec breadth

    • markers — 화살표와 dash 끝
    • text · textPath
    • paint-order · opacity · filters
    • arc flatten 통합
  • Part 15. Curve calculus

    • de Casteljau subdivision
    • flatness와 chord error
    • 곡률 κ와 법선
    • arc center parameterization
    • G¹ smooth — S와 T
    • shoelace signed area
  • Part 16. Intersection & proximity

    • segment intersection
    • line ∩ cubic · curve ∩ curve
    • closest point on curve
  • Part 17. Offset curves

    • normal offset sampling
    • offset cusps
  • Part 18. Transform algebra

    • affine inverse & decompose
    • transform path vs group
  • Part 19. Rational curves

    • circle as cubic — κ constant
    • rational curves & exact arcs
  • Part 20. Tessellation & pixels

    • convex triangulation · ear clipping
    • evenodd parity → pixels
  • Part 21. Compositing math

    • Gaussian blur kernel
    • Porter–Duff & premultiplied α
  • Part 22. Math topic map

    • SVG 수학 주제 지도
  • Part 23. SVG animation

    • SMIL — animate 속성
    • SMIL — animateTransform
    • SMIL — animateMotion
    • stroke dash draw-on
    • CSS offset-path motion
    • path morph
    • JS motion along path
  • Part 24. Motion precision

    • uniform speed along path
    • cubic–cubic intersection
    • SVGPathElement length API
    • SMIL keyTimes & keySplines
    • degree elevation Q→C
  • Part 25. GPU mesh & WAAPI

    • triangulation with holes
    • WAAPI + SVG attributes
    • evenodd fill + triangle mesh

flatness와 chord error

곡선 중점 B(½)가 끝점 현(chord) P0–P3에서 얼마나 떨어져 있는지가 flatness error입니다. 이 값이 tolerance 이하면 “이 구간은 직선으로 봐도 된다”고 말할 수 있습니다.

데모에서 볼 것

  • 회색 cubic + 점선 chord (P0–P3)
  • toolbar tolerance 0–20 px
  • readout: cubicFlatnessError = … px — chord에 대한 수직 거리(cross/chordLen)

tolerance를 낮추면 adaptive flatten(052)이 더 많이 subdivide(068)합니다.

측정 — cubicFlatnessError

import { cubicFlatnessError } from "svg-matrix-core";

const err = cubicFlatnessError(p0, p1, p2, p3);
// B(½)에서 chord P0→P3까지의 수직 거리 (px)
err = |(mid − P0) × chord| / |chord|

chordLen ≈ 0이면 끝점 거리로 fallback — degenerate segment.

quadratic:

import { quadraticFlatnessError } from "svg-matrix-core";

adaptive flatten과의 관계

engine.js의 flattenCubicAdaptive는 동일한 기하를 distancePointToSegment(B(½), P0, P3)로 검사합니다.

import { flattenCubicAdaptive, flattenPathSegmentsAdaptive } from "svg-matrix-core";

flattenCubicAdaptive(p0, p1, p2, p3, tolerance, points);
flattenPathSegmentsAdaptive(segments, { tolerance: 0.5 });
강의멈춤 기준점 개수
016고정 stepsPerCurve예측 가능·항상 많음
069 (여기)chord error ≤ ε곡률에 비례
052전체 path + compareFlattenMethodsfixed vs adaptive 비교 데모

flatness vs 다른 “곡률” 지표

지표비용의미
flatness (chord)매우 저렴“직선으로 대체해도 되나?”
070 cubicCurvatureAt κ미분 2회offset·법선·화살표
008 bbox 극값중간selection tight box

급격한 코너는 flatness가 크게 나와 subdivide가 깊어집니다 — 078 offset cusp와는 다른 현상.

교차 알고리즘

075 cubicCubicIntersections — 두 cubic이 각각 flat하면 control hull chord로 교차 검사, 아니면 068 subdivide. flatness가 broad-phase 역할.

함정

  • 픽셀 tolerance — zoom·viewBox에 맞게 ε 스케일 (world units vs screen px)
  • flatness는 전역 최대 오차 보장이 아님 — 구간 중점만 검사; 극히 pathological handle에서는 subdivide depth로 수렴
  • arc A — arcSegmentToCubics 후 cubic에 동일 adaptive (053)

Core API

  • cubicFlatnessError, quadraticFlatnessError — geometry.js
  • flattenCubicAdaptive, flattenPathSegmentsAdaptive — engine.js

관련

  • 068 subdivide · 052 · 017 length sampling 품질

오늘의 핵심

flatness는 “곡률이 큰가?”의 저렴한 근사입니다. flatten·intersection·boolean에서 ε 하나로 품질–성능을 맞추고, 정밀 법선·κ는 070으로 넘기세요.

최근 수정: 26. 5. 17. PM 4:35
Contributors: jinho.park.s3, Cursor
Prev
de Casteljau subdivision
Next
곡률 κ와 법선