Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7513473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:11:54+00:00 2026-05-30T00:11:54+00:00

There are some situations where there are multiple methods to calculate the same value.

  • 0

There are some situations where there are multiple methods to calculate the same value.

Right now I am coming up with an algorithm to “expand” a 2D convex polygon. To do this I want to find which direction to perturb each vertex. In order to produce a result which expands the polygon with a “skin” of the same thickness all around, the amount to perturb in that direction also depends on the angle at the vertex. But right now I’m just worried about the direction.

One way is to use atan2: Let B be my vertex, A is the previous vertex, and C is the next vertex. My direction is the “angular average” of angle(B-A) and angle(B-C).

Another way involves sqrt: unit(B-A)+unit(B-C) where unit(X) is X/length(X) yields a vector with my direction.

I’m leaning towards method number 2 because averaging angle values requires a bit of work. But I am basically choosing between two calls to atan2 and two calls to sqrt. Which is generally faster? What about if I was doing this in a shader program?

I’m not trying to optimize my program per se, I’d like to know how these functions are generally implemented (e.g. in the standard c libraries) so I’ll be able to know, in general, what is the better choice.

From what I know, both sqrt and trig functions require an iterative method to arrive at an answer. This is the reason why we try to avoid them when possible. People have come up with “approximate” functions which use lookup-tables and interpolation and such to try to produce faster results. I will of course never bother with these unless I find strong evidence of bottlenecking in my code due to just these routines or routines heavily involving them, but the differences between sqrt, trig funcs, and inverse trig funcs may be relevant for the sake of discussion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:11:55+00:00Added an answer on May 30, 2026 at 12:11 am

    With typical libraries on common modern hardware, sqrt is faster than atan2. Cases where atan2 is faster may exist, but they are few and far between.

    Recent x86 implementations actually have a fairly efficient sqrt instruction, and on that hardware the difference can be quite dramatic. The Intel Optimization Manual quotes a single-precision square root as 14 cycles on Sandybridge, and a double-precision square root as 22 cycles. With a good math library atan2 timings are commonly in the neighborhood of 100 cycles or more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there some practical programming situations for someone to declare a class abstract when
I have a form with multiple fields that I'm validating (some with methods added
Is there some shortcut way of handling multiple properties on a class (say 50
There is the situation - i made some math modelling app on C#(WPF), showing
Is there some means of querying the system tables to establish which tables are
Is there some way I can use URLs like: http://www.blog.com/team-spirit/ instead of http://www.blog.com/?p=122 in
Is there some built-in way to share files between Xen guests? I don't currently
Is there some way to block access from a referrer using a .htaccess file
Is there some way to hide the browser toolbar / statusbar etc in current
Is there some rare language construct I haven't encountered (like the few I've learned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.