# Octile distance of 2 octants?

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

## 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);

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

Thanks

Jack

##### Share on other sites

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 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 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

Have a nice day.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 10
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634147
• Total Posts
3015785
×