• Advertisement
Sign in to follow this  

unit cube question

This topic is 2682 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

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


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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.

Share this post


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

  • Advertisement