Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

Octile distance of 2 octants?

This topic is 846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

//float dx = fabs((float)m_vPivot.x - other->m_vPivot.x);
//float dz = fabs((float)m_vPivot.z - other->m_vPivot.z);
//return std::max(dx, dz) + (SQRT2 - 1) * std::min(dx, dz);

 

Here is the octile distance of 2 quads in a quadtree.

What about the same for 2 octants? (y taken into account)

Thanks

Jack

 

Share this post


Link to post
Share on other sites
Advertisement

Is that actually the distance between two nodes in a quad tree? It looks like a malformed Manhattan distance. Where does the sqrt2 - 1 come from? 

 

Are you only able to move left/right, up/down and forward/back?

 

For manhatten distance you can check this out:

https://en.wikipedia.org/wiki/Taxicab_geometry

But it is basically:

float dx = fabs((float)m_vPivot.x - other->m_vPivot.x);
float dy = fabs((float)m_vPivot.y - other->m_vPivot.y);
float dz = fabs((float)m_vPivot.z - other->m_vPivot.z);
return dx + dy + dz;

Perhaps I am missing something though as I'm not sure why the sqrt2-1 is there.

 

Edit: I see what you mean now, you also have diagonal movement.

 

This is a bit more tricky, I don't have a neat formula but there probably is one, this is more algorithmic

You need to work out the 3 differences as above and then you will get

dx, dy, dz

float min = min(dx, dy, dz);
float max = max(dx, dy, dz);
mid = // whatever value is left

float dist = 0;
dist += sqrt(3)*min;
max -= min;
mid -= min;
dist += sqrt(2)*mid;
max -= mid;
dist += max;

return dist;

It is looking at how many times you can move in 3 directions at once (which will be a distance of sqrt(3)) then how many times you can move in 2 directions at once (which will be sqrt(2)) and finally how many times you can move in only 1 direction.

Edited by Nanoha

Share this post


Link to post
Share on other sites
mid = // whatever value is left 

May I ask what this line means?

BTW, actually, I am not using the center point as the pivot,

I am actually using the lowest y inside the voxel

and x and z are at the center of it (the lower plane of the voxel).

Thanks

Jack

 

Share this post


Link to post
Share on other sites

 

mid = // whatever value is left 

May I ask what this line means?

BTW, actually, I am not using the center point as the pivot,

I am actually using the lowest y inside the voxel

and x and z are at the center of it (the lower plane of the voxel).

Thanks

Jack

 

 

 

You need to sort the distances, max and min are as the name suggests, mid is the middle or whatever value is left. So if you had 3 distances dx=5, dy=2, dz=4 then max=5, min = 2 and mid would be 4. It should be ok if your y-value is the floor of your voxel (it's all just relative after all).

Edited by Nanoha

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!