Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

atan2() — angle from two coordinates

atan2() derives an angle from two dimensionally compatible components while retaining quadrant information.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

atan2(<calc-sum>, <calc-sum>)

atan2() uses atan2(<calc-sum>, <calc-sum>) and derives an angle from two dimensionally compatible components while retaining quadrant information. The result keeps the type required by the property grammar, so the function participates in value computation rather than text substitution.

The example sets a real CSS property: atan2(1, -1) computes to 135deg. The deliberate comparison with the one-argument atan(-1), which computes to -45deg, demonstrates that the two-argument function retains quadrant information. The value comes from getComputedStyle and therefore exercises the computed-value stage.

Boundary behavior: arguments need the same numeric type, and a zero pair depends on signed-zero rules.

Examples

const a=document.createElement('div'),b=document.createElement('div');document.body.append(a,b);a.style.rotate='atan2(1, -1)';b.style.rotate='atan(-1)';console.log('atan2='+getComputedStyle(a).rotate+'; atan='+getComputedStyle(b).rotate);

Result

atan2=135deg; atan=-45deg

atan2() derives an angle from two dimensionally compatible components while retaining quadrant information.

Sources