$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.

CategoryMath
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

{ $atan: <numeric-expression> }

⚙️ Parameters

numeric valueA 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

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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏