The SDF of a Line Segment

107K views · 6 years ago · tutorial · intermediate · evergreen

Inigo Quilez derives the signed distance function of a line segment, one of the basic building blocks of shader-based shape drawing. He builds the shape from equations step by step.

HN people recommend Quilez's SDF videos as an illuminating way to use equations to describe geometry.

“videos which give an illuminating perspective on using equations to describe geometry”

2 comments from Hacker News

R
@RossBencina2025 · in “Ask HN: What to learn for math for modeling?”
For geometry, start with high-school algebra and coordinate geometry, and learn how to put the two together: equations representing geometry. By which I mean, being able to write down equations for geometric objects and manipulate the equations to get them into different useful forms, and to compute useful things. A first example would be studying different ways of writing down equations for the line [1], and then learn how each of the forms relate, how to use algebra to move between them, and what each for is useful for. For example finding the intersection of two lines involves simultaneously solving for (x,y) that satisfy both equations, and there's a particular form that is best suited to that. Another form is better if you want to "move along a line" say, parameterised by time. One form might be best for GPU rendering. Once you're comfortable with algebraic expressions for lines, then you can move on to the more complex curves that you listed -- the equations for these curves can be manipulated in analogous ways. EDIT: importantly you want to learn not how to "plug and chug" numbers, but instead how to use these equations in code: e.g. how would you use the equations to write code to draw a line/curve, and how to derive functions to intersect curves, connect curves at tangents, etc. There's more to it than that of course. For example working out equations for tangents to curves will become important. But start with the above. You mention de casteljau algorithm, I am not familiar with that, but it looks like it might be heading more into algebra, in particular manipulating polynomials, which you learn to write down in high-school, study more in pre-calculus and calculus, but can get pretty complicated, for example if you want to solve a quintic equation. Two elementary books: McDougal, Little, "Geometry for Enjoyment and Challenge" Joseph H. Kindle, "Theory and Problems of Plane and Solid Analytic Geometry (Shaum's outline)" The following are approachable, but don't directly address your interest in curves: Joseph O'Rourke, "Computational Geometry in C," second edition (basics everyone should know, starts with primitives like knowing the best way to compute the intersection of two line segments. Christer Ericson, "Real-time collision detection" (a bit more specific, but a fantastic book, recommended to me here on HN in the past) And of course I must reference Inigo Quilez' [2] "SDF of a ..." videos which give an illuminating perspective on using equations to describe geometry[3]. [1] link)/07%3A_Straight_Lines/7.05%3A_Forms_of_the_Equation_of_a_Line [2] link [3] SDF of a Line ▶ this video EDIT: some of the IRC servers have #math channels, and some of those are open to drop ins asking questions like yours (others seem to be full of people studying for exams).
RecommendsView on HN
j
@jmiskovic2020 · in “Getting started with shaders: signed distance functions”
I was surprised to learn he was behind the Oculus Quill (VR art and animation software). He started posting very well produced video lessons on SDFs. I enjoyed this recent one: ▶ this video
RecommendsView on HN