|
-
Mar 5th, 2005, 04:32 PM
#1
Thread Starter
Not NoteMe
An ND array in a 1D array
I want to represent a binary tree, quad tree, oct tree etc. as one generic tree structure that can be used for any.
I've got a 1D array, that holds the children of a tree data structure.
The tree has the number of dimensions associated with it.
The number of children it has is:2^Dimensions since i'm divining things in two, for each dimension.
What i'm doing with the tree is dividing up an ND space into equil parts. i.e. for 2D space i'd need 4 chidren etc.
The trouble i'm having is when i come to work out the upper and lower bounds of each child (given the upper and lower bounds of the parent).
I need a way of knowing, for a given dimension (e.g. X,Y,Z...) in a given child (indexed in trhe 1D array), what the upper and lower bounds would be for this child
Thanks for any help, i'm really stuck with this and i need a solution pretty soon.
Sorry for the dodgy explanation, here's what i did with 3 dimensions, which may or may not help:
Code:
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
for(int k=0;k<2;k++)
{
//Setup boundaries
m_pChildren[i][j][k]->m_pLowBounds[0] = (byte)(m_pLowBounds[0] + i * ((m_pHighBounds[0] - m_pLowBounds[0])/2.0f));
m_pChildren[i][j][k]->m_pHighBounds[0] = (byte)(m_pLowBounds[0] + (1+i) * ((m_pHighBounds[0] - m_pLowBounds[0])/2.0f));
m_pChildren[i][j][k]->m_pLowBounds[1] = (byte)(m_pLowBounds[1] + (j * ((m_pHighBounds[1] - m_pLowBounds[1])/2.0f)));
m_pChildren[i][j][k]->m_pHighBounds[1] = (byte)(m_pLowBounds[1] + (1+j) * ((m_pHighBounds[1] - m_pLowBounds[1])/2.0f));
m_pChildren[i][j][k]->m_pLowBounds[2] = (byte)(m_pLowBounds[2] + k * ((m_pHighBounds[2] - m_pLowBounds[2])/2.0f));
m_pChildren[i][j][k]->m_pHighBounds[2] = (byte)(m_pLowBounds[2] + (1+k) * ((m_pHighBounds[2] - m_pLowBounds[2])/2.0f));
}
}
}
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|