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 6716567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:44:57+00:00 2026-05-26T08:44:57+00:00

what are the differences between using these two algorithms. I’ve always wondered how I

  • 0

what are the differences between using these two algorithms. I’ve always wondered how I should be optimising things.How do they differ memory and speed wise? Is one better than the other? Aside from code clarity I mean.

this is the first version I had:

bool Intersects(BoundingSphere boundingSphere)
{
    D3DXVECTOR3 vectorBetween = (centre - boundingSphere.centre);

    // works out the distance between the sphere centre's using pythag
    float distance = sqrt(
                         pow(vectorBetween.x, 2) 
                       + pow(vectorBetween.y, 2) 
                       + pow(vectorBetween.z, 2));

    // if two radius's add to more than the distance between the centres
    return (radius + boundingSphere.radius > distance);
}

This method is the same, but it doesn’t hold any values in variables, it just uses one long calculation

bool Intersects(BoundingSphere boundingSphere)
{
    return (radius + boundingSphere.radius >
            (sqrt(pow((centre - boundingSphere.centre).x, 2) +
                  pow((centre - boundingSphere.centre).y, 2) +
                  pow((centre - boundingSphere.centre).z, 2))));
}
  • 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-26T08:44:58+00:00Added an answer on May 26, 2026 at 8:44 am

    The two algorithms will, under proper optimization options, compile down to exactly the same code. Since the first is far more readable, it is undoubtedly the better of the two.

    The correct way to optimize this code is not to get rid of the variables (the compiler can do that for you), but to get rid of the sqrt operation: just compare squared distances.

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

Sidebar

Related Questions

What are the differences between these two code snippets? Using type : import types
What is the difference between these two: font-style:italic font-style:oblique I tried using the W3Schools
I am confused on the differences between these two code blocks: $(#someButton).click(function() { var
Are there differences between these two? replace(/[^a-z0-9]/gi, ''); replace(/[^a-zA-Z0-9]/g, ''); Also, are there any
What is the differences between those 2 assuming I'm using SQL Server as my
these two algorithms are used to check valid member numbers the first is the
I need to be able to compute differences between two data/time values which represent
Is there a difference between using a makefile and a Makefile?
Is there a difference between using exit() or just return statements in main() ?
Is there a difference between using tearDown and setUp versus __init__ and __del__ when

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.