Original Post
I'm trying to do basically do point cloud alignment, but aligning to a specific plane. I'm generating a heightmap form the points, but they're slightly sloped, with that i mean, the ground plane isn't on the x and y plane, but rather sloped up. so i want to align it back down, in order for the heightmap to not be rotated by a certain angle. i calculated my eigenvectors and ended up with -0.8703 -0.0393 -0.0905 0.0000 -0.3573 -0.6427 0.0002 -0.3027 -0.6972 but then i'm stuck, i don't know what to do next in order to do what i want. i've tried multiplying all 3d points with a matrix made up of the eigenvector, and that didn't work, i tried multiplying them by a 3x3 rotation matrix created by using the 1st and 2nd eigenvectors and this code,
float** MathUtil::calculateAlignmentRotMat(float* a, int al, float* b, int bl) {
float angle = acosf(dot3(a, b));
float* rotationAxis = cross3(a, b);
return calculateRotationMat(rotationAxis, angle);
}
float** MathUtil::calculateRotationMat(float* rotationAxis, float angle) {
float **result = new float*[3];
for (int i = 0; i < 3; i++)
result = new float[3];
float rx = rotationAxis[0];
float ry = rotationAxis[1];
float rz = rotationAxis[2];
delete[] rotationAxis;
float cosAngle = cosf(angle);
float sinAngle = sinf(angle);
float c = 1.0 - cosAngle;
result[0][0] = cosAngle + rx * rx * c;
result[1][0] = rz * sinAngle + ry * rx * c;
result[2][0] = -ry * sinAngle + rz * rx * c;
result[0][1] = -rz * sinAngle + rx * ry * c;
result[1][1] = cosAngle + ry * ry * c;
result[2][1] = rx * sinAngle + rz * ry * c;
result[0][2] = ry * sinAngle + rx * rz * c;
result[1][2] = -rx * sinAngle + ry * rz * c;
result[2][2] = cosAngle + rz * rz * c;
return result;
}
but that also didn't work. my general apply function is
rotMatrx = util->calculateAlignmentRotMat(vecRot[0], m, vecRot[1], m);
float* interm2 = vector(m+1);
float* tempm = vector(m+1);
/* Form projections of row-points on first three prin. components. */
/* Store in 'realData', overwriting original data. */
for (i = 0; i < realN; i++) {
for (j = 0; j < m; j++) {
interm2[j] = realData[j];
}
interm2[3] = 1;
/* data[j] will be overwritten */
for (k = 0; k < 3; k++) {
for (k2 = 0; k2 < m; k2++) {
tempm[k2] += interm2[k2] * rotMatrx[k][k2];
}
}
realData[0] = tempm[0];
realData[1] = tempm[1];
realData[2] = tempm[2];
}
I really hope someone can help me out with this, Thanks Phyx