Centering a point cloud/OBJ object

Hi all,

I have a problem locating on the canvas a large point cloud file (.txt / .xyz) that I have created with Meshlab.

I’ve tried to translate the coordinates numerous times with the translate() function but not only I can’t seem to center the point cloud but also I’m unable to find it on the screen.

The file looks like this:

298422.156250 3.039000 -59934.984375 0.830097 1.000000 -2.509439 
298431.875000 3.039000 -59918.578125 1.011246 5.000000 -1.724044 
298434.750000 3.039000 -59921.472656 -1.559582 2.000000 -2.399486 
298442.562500 3.039000 -59922.582031 0.195280 1.000000 -2.859333 
298447.593750 3.039000 -59919.855469 1.427991 3.000000 -2.638340 
298462.968750 3.039000 -59911.554688 1.806006 5.000000 -1.242686 
298447.750000 3.039000 -59886.371094 2.543457 5.000000 1.589585 
298443.500000 3.039000 -59880.003906 2.470000 3.000000 1.701539 
298426.093750 3.039000 -59856.257812 2.401855 12.000000 1.797043 
298424.218750 3.039000 -59853.851562 1.324241 1.000000 2.196671 
298422.906250 3.039000 -59854.195312 -0.759176 2.000000 2.902353 
298401.062500 3.039000 -59859.894531 -0.761293 2.000000 2.901793

the first 3 columns are the x, z and y coordinates

Similarly, I have loaded a .obj object (built from the same coordinates) with the loadShape() function I’m facing the same issue.

What kind of translation do you think I need to operate (from looking at the snippet) ?
Do you think it’s a problem of scaling ?

I think you need to translate to width/2 height/2 then scale it down … a lot! Mind you, that depends if the values are around zero. What’s the minimum and maximum values for each dimension?

Hi @neilcsmith, thanks for the reply.

width/2, height/2 translation doesn’t work. I mean I can see a tiny point cloud (I have scaled down to .001) but I have to rotate the camera (PeasyCam) with the mouse and it’s very far.

column 1:

  • min(): 298393.84375
  • max(): 307484.0

column 2:

  • min(): 11.891999999999999
  • max(): 547.76000999999997

column 3:

  • min(): 78599.117188000004
  • max(): 59277.414062000003

You could try translating by the negative of the min value in each direction? You could then scale it based on the ratio of width to the difference of max and min.

I tried already. I also tried the negative mean of each column, didn’t work either. This thing is a real headache.

So it seems I wasn’t using the translate(), rotate() and scale() functions in the correct order. The following did the trick.

translate(-302938.921875, -267.93400499, 68938.265625)

The translate() coordinates are the negative means of each column.

However, applying that exact translation to an .obj built from the very same vertices doesn’t put that object at the center. It appears on the canvas, but far from the camera and at a different angle. Very strange.

I would expect to use translate before scale. And I’d start with negative min, not mean. The idea is to end up with the min values at zero.

Logic would have it that scale() goes after translate(), as you’re suggesting, but for some reason it’s the exact opposite that works here. Don’t know why.

I prefer putting the negative mean because it makes possible to rotate the point cloud around its centroid.

Yes, but I’d be tempted to do those in two steps, at least at first. Get your points normalized to the window (translate then scale), then move it to the centre. By the way, are you using PeasyCam all the time? Have you tried without just in case?

Just noticed your translate line above has a positive z translation - is that intended?!

Apologies for the late reply.

Yes, the translate line has a positive z translation and it works fine this way.
Yes, I’m using PeasyCam and your suggestion is relevant, I’ll try adjusting the coordinates without the library first.

Really?! Why are you asking the question then? :wink: If you want to make everything around 0,0,0 then you need to negatively translate all 3 axes first.

Simply because it didn’t work. Negatively translating all the axes makes the object totally disappear from screen. With or without peasycam, before or after scaling…

I’ll stick with the dubious workaround aforementioned: scaling first and translating by negative means.