# unit cube question

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

## Recommended Posts

I have a simple problem. I need to map a point unto a unit cube which extends from 0 to 1 in all axis; Right now, this is how I am mapping it. However, it does not account for a negative in the point (making it actually map the point from -1 to 1). How can I fix this?

x = (p.x/sqrt(maxX*maxX+maxY*maxY+maxZ*maxZ));
y = (p.y/sqrt(maxX*maxX+maxY*maxY+maxZ*maxZ));
z = (p.z/sqrt(maxX*maxX+maxY*maxY+maxZ*maxZ));

Thank You.

EDIT: Also, this has a problem of funky-scaling the point when I translate it. How do I make sure that it does not do that, and only scale it when it reaches the borders of the unit cube?

##### Share on other sites
I think your question is a bit ambiguous, is this what you're asking?

You have a unit sized cube.
You've got a point p, which can be thought of as a direction.
If you follow the direction from the origin it will go through a face of the cube at point B. Is B what you want?

##### Share on other sites
I have a unit cube and a collection of 3D objects (O1,O2,O3), each of which are made up of points. I am trying to fit all the objects inside a unit cube so that all of them are visible on the screen in any point in time.

Thank you

##### Share on other sites
So I assume the maxX maxY and maxZ represents the maximum extents of your points and I guess you also have minX, minY, minZ?

For each of the axes I'd do:
size = (maxValue - minValue) * 0.5
midpoint = minValue + size

then for each point in the model/model collection:
newPosition = (p - midPoint) / size

But I'd prefer to do it with a matrix, in which case it is just a translate and a scale:
translate(-midPoint)
scale(1/size)

I'm just doing things with one dimension here, hope that makes sense.

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633395
• Total Posts
3011653
• ### Who's Online (See full list)

There are no registered users currently online

×