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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:30:53+00:00 2026-06-02T19:30:53+00:00

Using the new XMVECTOR and XMFLOAT3 classes what is the best way to get

  • 0

Using the new XMVECTOR and XMFLOAT3 classes what is the best way to get the distance between 2 points? I couldn’t find a function that does it in XMVector* family of functions so I came up with the following :

float distance(const XMFLOAT3& v1,const XMFLOAT3& v2)
{
    XMVECTOR vector1 = XMLoadFloat3(&v1);
    XMVECTOR vector2 = XMLoadFloat3(&v2);
    XMVECTOR vectorSub = XMVectorSubtract(vector1,vector2);
    XMVECTOR length = XMVector3Length(vectorSub);

    float distance = 0.0f;
    XMStoreFloat(&distance,length);
    return distance;
}

Will this be faster than a normal Vector3 class with just 3 floats for x,y,z and then using sqrt because it uses intrinsic optimizations? Namely :

float Distance(const Vector3& point1,const Vector3& point2)
{
    float distance = sqrt( (point1.x - point2.x) * (point1.x - point2.x) +
                            (point1.y - point2.y) * (point1.y - point2.y) +
                            (point1.z - point2.z) * (point1.z - point2.z) );
    return distance;
}
  • 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-06-02T19:30:54+00:00Added an answer on June 2, 2026 at 7:30 pm

    There’s only one way to get distance between points. And that’s the way you described. vec3 diff = b - a; float distance = sqrtf(dot(diff, diff));

    Will this be faster than a normal Vector3 class with just 3 floats for x,y,z and then using sqrt because it uses intrinsic optimizations?

    If you’re worried about performance, you need to profile your application, instead of trying to guess what will be faster. There’s a very good chance that impact of of “less efficient” solution will be completely unnoticeable in your application.

    There’s also a very good chance that if you start writing routines yourself, you’ll make them less efficient or introduce bugs. For example your “hand-written” code might (depending on compiler) perform more floating point calculations than original code that uses “XMVECTOR”. In your routine you calculate difference between vectors twice. If compiler doesn’t optimize that out, you’ll end up with 6 subtractions, 2 additions, 1 sqrtf, and 3 multiplications. In “XMVECTOR” code you’ll use 3 subtractions, 2 additions, 3 multiplications, and 1 sqrtf.

    For profiling applications you can use AQTime 7 Standard (free at the moment), or gprof (if you’re compiling with gcc/g++).

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

Sidebar

Related Questions

Using new style classes (I'm in python 3.2) is there a way to split
when using new Date,I get something like follows: Fri May 29 2009 22:39:02 GMT+0800
I'm using new style classes in Python 2.6 and am having trouble with __getattr__
When you allocate an array using new [] , why can't you find out
Is it forbidden or not a best practice to create objects using new. Creating
I created a CultureInfo object using new CultureInfo(fr-FR). Now I have a number that
The closest I get is using new FileInfo(path).FullPath , but as far as I
Is there a difference between using PHPs time() and using new MongoDate() ? I
I want to understand better the difference between using 'new' to allocate memory for
I need to call function whenever class is created using new. Currently I need

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.