Special cases, in front of me, light on a floor
The picture shows the 60 degree light: white is the floor's normal N, orange is the direction L towards the light.
The dot product tells you how much two directions agree: 1 when they match, 0 at a right angle, negative when they oppose. The cross product gives a new direction at right angles to both. Lighting, culling and surface directions all use them.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
A triangle has corners P0 = (0, 0, 0), P1 = (1, 0, 0) and P2 = (0, 1, 0). Compute its normal with three.js and say which way it faces.
Write isInFront(camera, point) that returns true when point is in front of a camera that looks along its own forward direction.
Explain it without notes
A light shines from direction L onto a surface with normal N. How does the brightness depend on them, and why is it clamped at 0?
Why do a.cross(b) and b.cross(a) give different answers, and when is the result the zero vector?
Console
Nothing logged yet.Expected console output
parallel: dot 3, cross (0, 0, 0), angle 0
perpendicular: dot 0, cross (0, 0, 2), angle 90
opposite: dot -2, cross (0, 0, 0), angle 180
one is zero: dot 0, cross (0, 0, 0), angle 90
camera forward = (0, 0, -1)
post ahead: dot 1.00 in front
post behind: dot -1.00 not in front
post to the side: dot 0.00 not in front
light 0 degrees from vertical: N . L = 1.00, brightness 1.00
light 60 degrees from vertical: N . L = 0.50, brightness 0.50
light 90 degrees from vertical: N . L = 0.00, brightness 0.00
light 120 degrees from vertical: N . L = -0.50, brightness 0.00