CSS Graphics Geometry
Guide
Reference
GitHub
Guide
Reference
GitHub
  • Part 0. Math foundations

    • 좌표계와 CSS pixel
    • 점, 벡터, 거리와 기본 용어
    • 각도, 라디안, atan2
  • Part 1. Transform linear algebra

    • translate, scale, rotate
    • CSS matrix(a,b,c,d,e,f)
    • 변환 순서와 transform-origin
    • local, world, screen 좌표계
    • inverse matrix와 포인터 입력
    • 좌표와 transform 디버깅
  • Part 2. Infinite canvas math and architecture

    • viewport와 camera 모델
    • cursor anchored zoom
    • ruler와 tick 계산
    • 주기 함수와 grid step
    • content, overlay, controls layer
    • scene graph와 nested transform
  • Part 3. Editor tool math

    • Pointer Events와 드래그
    • DOMRect와 getBoundingClientRect
    • hit testing과 bounding box
    • selection rectangle과 marquee
    • selection bounds와 handles
    • resize와 rotation handle
    • snapping과 smart guides
    • group, frame, clipping
  • Part 4. CSS graphics properties as math

    • CSS box로 도형 만들기
    • clip-path, radius, shadow
    • 선형보간과 linear-gradient
    • 거리 함수와 radial/conic-gradient
    • stacking context와 합성
    • layout, paint, composite
  • Part 5. Editor state and persistence

    • 레이어 모델과 z-index
    • 이동, 복제, 삭제, 잠금
    • undo/redo command model
    • JSON export/import
  • Part 6. SVG overlay and vector editing

    • SVG viewBox와 좌표계
    • getScreenCTM과 inverse
    • SVG pointer-events와 stroke hit testing
    • cubic bezier path editing
    • mask, clipPath, marker
  • Part 7. Figma to CSS translation

    • Figma node와 CSS DOM 모델
    • Frame constraints와 Auto Layout
    • Fills, strokes, effects를 CSS로
    • Vector와 text 변환
    • gradient 밖의 CSS 수학
    • Figma gradient를 CSS gradient로 변환하기
    • 수학이 필요한 Figma to CSS 속성들
    • Figma VectorNetwork 정리
  • Appendix A. Canvas renderer transition

    • Canvas로 넘어가는 기준
  • Appendix B. Motion and timing

    • 모션 수학과 timing 함수
    • Keyframe timeline 엔진
    • Motion path 수학
    • Bezier curve 길이 구하기

getScreenCTM과 inverse

이번에는 SVG에서 포인터 좌표를 되돌리는 방법입니다.

HTML 쪽에서는 getBoundingClientRect()와 DOMMatrix를 봤습니다. SVG에는 getScreenCTM()이라는 함수가 있습니다. CTM은 current transformation matrix입니다. 이름은 딱딱하지만 역할은 익숙합니다.

SVG 내부 좌표가 screen으로 가는 matrix를 알려줍니다.

getScreenCTM은 화면까지의 변환이다

screenPoint = CTM * svgPoint
svgPoint = inverse(CTM) * screenPoint
CTM includes viewBox transform and ancestor transforms
SVG CTM inverse pointer diagramscreen = CTM * svgsvg = inverse(CTM) * screenCTM includes viewBox and transforms
getScreenCTM은 SVG local 좌표에서 screen 좌표까지 가는 전체 변환입니다. 포인터 입력은 inverse를 곱해 local로 되돌립니다.

포인터는 clientX/clientY로 들어옵니다. 이 screen point를 SVG 내부 좌표로 바꾸려면 CTM의 inverse를 곱합니다.

const point = new DOMPoint(event.clientX, event.clientY);
const svgPoint = point.matrixTransform(element.getScreenCTM().inverse());

이 패턴은 path point picking, connector endpoint dragging, vector handle editing에서 자주 씁니다.

CSS transform과 SVG transform이 섞일 때

SVG의 transform과 CSS의 transform이 같이 쓰이면 좌표 변환 체인을 더 꼼꼼히 봐야 합니다. 브라우저가 어떤 transform까지 CTM에 포함하는지 테스트로 확인하는 편이 안전합니다.

레이아웃이나 viewBox가 바뀐 뒤에는 CTM도 다시 읽어야 합니다. 예전 matrix를 들고 있으면 포인터가 살짝 다른 세계로 갑니다.

데모에서 볼 것

데모에서는 SVG를 scale/translate한 뒤 포인터 좌표가 path 좌표로 정확히 변환되는지 확인합니다.

오늘의 핵심은 HTML이든 SVG든 결국 같은 이야기라는 점입니다. 화면 좌표로 들어온 포인터를 inverse matrix로 내부 좌표에 데려옵니다.

Edit this page
최근 수정: 26. 5. 14. PM 5:45
Contributors: easylogic
Prev
SVG viewBox와 좌표계
Next
SVG pointer-events와 stroke hit testing