$atan (Arctangent)
Last updated: 2026-10-09
$atan (Arctangent)
$atan returns the arctangent of a number in radians, accepting any real input. It is used to convert slopes to angles or compute directions, such as deriving a grade angle from a slope, or computing an incline angle from elevation difference and horizontal distance. A null or missing argument yields null; results fall between -π/2 and π/2. It is the inverse of $tan. When you need the quadrant from both x and y components, prefer $atan2, which distinguishes all four quadrants.
| Category | Math |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
{ $atan: <numeric-expression> }
⚙️ Parameters
| numeric value | A numeric expression of any real value. |
|---|
Returns:The arctangent in radians; null when null or missing
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// $atan: angle (radians) from a slope
db.trig.aggregate([
{ $project: {
angle: { $atan: '$slope' }
} }
])
Output:
{ '_id': 1, 'angle': 0.7853981633974483 }
{ '_id': 2, 'angle': 1.1071487177940904 }
📌 Notes
- Accepts any real input; results fall between -π/2 and π/2
- The result is in radians; convert with $radiansToDegrees
- Use $atan2 when the quadrant matters
🏷️ Related Tags
💡 Related Cases
More hands-on cases coming soon.
📚 Related Tutorials
❓ FAQ
QWhat is the difference between $atan and $atan2?
A$atan takes a single slope while $atan2 takes y and x components and resolves the correct quadrant.
QWhat unit does $atan return?
ARadians; use $radiansToDegrees for degrees.
QWhat is $atan(1)?
AIt is π/4, the radian measure of 45 degrees, about 0.7854.