Scaling 3D points

Hi,

I have a set of points and a 3D grid of length 4 x 2.5 x 4. The grid is always displayed at the origin and the points may vary depending on the text file they are being read in from.

The problem I have is I am unsure how to scale the points, so that they retain the correct distances between each other, to fit in the grid. With no scaling the points can appear in the to right of the screen and the grid in the centre.

Can someone please help me or point me in the direction of where I might get the correct calculations for this problem.

Thanks in advance.

um… man, can you describe your problem again? not sure if i understand what you need. how you draw these “points” and “grid”? grid with GL_LINES? points are point sprites, or GL_POINTS? or some overlay images?

I am using GL_LINES to draw the grid and GL_POINTS to draw the points. I know that I can scale to fit for 2D if I bring the min x axes value to 0 and then readjust the y axes accordingly so that they do not loss any of the distance measurements between them however I am unsure how to do this for 3D system with xyz points. Also I have to take into account the interval scale of the grid and the data file may not be the same every time I run the program. I am unsure how to do this so that I can scale the points into the grid whilst retaining the distance between the points and keeping them in perspective of the interval scale.

still not sure what is the problem with scaling GL_POINTS cam be resized with glPointSize(float size); what rescaling you are talking about?

It appears to me that you want to fit the points’ bounding box into that “grid”, a rectangle with one corner at the origin and width/height/depth along X/Y/Z axes, respectively.

  • determine the bounding box by determining min/max of the points’ x, y, and z coords individually.
  • calculate rectangle sizes divided by variation along the respective axes, x1=width/(xmax-xmin);y1=height/(ymax-ymin);z1=depth/(zmax-zmin);
  • obtain new point coords x’=x1*(x-xmin); y’=y1ymin; z’=z1(z-zmin);