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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:33:59+00:00 2026-05-12T11:33:59+00:00

I would like to test if a point is within a particular distance of

  • 0

I would like to test if a point is within a particular distance of a sphere.

So you have these variables…

Point3F spherePnt;
F32 sphereRadius;
Point3F testPnt;

I could do…

F32 dist = ( spherePnt - testPnt ).len() - sphereRadius;

If dist is positive it is outside the radius, if dist is negative it is inside the radius.

Or as an optimization to avoid the square-root inside the len() function you might try this…

F32 dist = ( spherePnt - testPnt ).lenSquared() - ( sphereRadius * sphereRadius );

Ok this looks like it makes since at first glance, but apparently its actually giving me incorrect results.

For example, given variables are setup like this…

SpherePnt( 0, 0, 0 )
SphereRadius( 1 )
testPnt( 1, 1, 1 )

Take the result of…

F32 dist = ( spherePnt - testPnt ).len() - sphereRadius;
F32 dist2 = mSqrt( ( spherePnt - testPnt ).lenSquared() - ( sphereRadius * sphereRadius ) );

dist = 0.7320508075688772935274463415059;
dist2 = 0.4142135623730950488016887242097;

It is pretty obvious that this is in fact, wrong, mathematically. It reduces to expecting the square root of 2 to be the same as the square root of 3… so the question is, I guess…

Given that I DO want to perform this test, “is point p within range r of a sphere”, is there a way to do this while avoiding the square root?

  • 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-12T11:33:59+00:00Added an answer on May 12, 2026 at 11:33 am

    You don’t need the sqrt computation in the “squared distances” approach! The distance between the two points (sphere center and testpoint) is less than the sphere radius iff the squared distance is less than the squared radius — for the sole purpose of testing “within the sphere or out of it?”, the fact that the square root of the difference is NOT the difference of the square roots, is totally irrelevant.

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

Sidebar

Related Questions

I would like to test a string containing a path to a file for
I would like to test a function with a tuple from a set of
I would like to test some exception handling logic in the empty catch block
I would like to test an app that uses the Clipboard (WindowsForms) and I
I would like to test a web app that was drastically redesigned to use
I would like to do a test like: http://stevelibonati.wordpress.com/2012/02/05/spring-mvc-test-with-a-sprinkle-of-mockito/ My problem is that I
I would like to test if an instance variable lies in a range of
I would like to test my JDO - DAO with multiple threads in order
I've nearly finished the development of a project and would like to test its
I have an odd problem that is crashing my app, that I would like

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.