What do these programming formulas for 3D coordinate processing implement?

82 Views Asked by At

I am studying a C++ program related to 3D coordinates and can not understand what two formulas implemented are doing so I need help in understanding the meaning of the lines (indicated below)

for (int i = 5; i<= 95; i++){
     float depth = sqrt (point[i].x * point[i].x +
                         point[i].y * point[i].y +
                         point[i].z * point[i].z ) ;

     float depth2 = sqrt (point[i+1].x * point[i+1].x +
                          point[i+1].y * point[i+1].y +
                          point[i+1].z * point[i+1].z ) ;

     if (depth1 > depth2) {
        // These lines. What's the significance of "* depth2 / depth1"
        diffX = points[i+1].x - points[i.x] * depth2 / depth1;
        diffY = points[i+1].y - points[i.y] * depth2 / depth1;
        diffZ = points[i+1].z - points[i.z] * depth2 / depth1;

        // Also the condition here. What does "/ depth2" achieve?
        if (sqrt(diffX*diffX + diffY*diffY + diffZ*diffZ) / depth2)  < 0.1 ) 
        {
           cloudNeighbourPicked[i-5] = 1 ;
           cloudNeighbourPicked[i-4] = 1 ;
           cloudNeighbourPicked[i-3] = 1 ;
           cloudNeighbourPicked[i-2] = 1 ;
           cloudNeighbourPicked[i-1] = 1 ;
           cloudNeighbourPicked[i] = 1 ;
        }
     }
     else {
        // Now its "* depth1 / depth2". Why?
        diffX = points[i+1].x * depth1 / depth2 - points[i.x] ;
        diffY = points[i+1].y * depth1 / depth2 - points[i.y] ;
        diffZ = points[i+1].z * depth1 / depth2 - points[i.z] ;

        // Now its "/depth1". Why?
        if (sqrt(diffX*diffX + diffY*diffY + diffZ*diffZ) / depth1)  < 0.1 ) 
        {
           cloudNeighbourPicked[i+1] = 1 ;
           cloudNeighbourPicked[i+2] = 1 ;
           cloudNeighbourPicked[i+3] = 1 ;
           cloudNeighbourPicked[i+4] = 1 ;
           cloudNeighbourPicked[i+5] = 1 ;
           cloudNeighbourPicked[i+6] = 1 ;
        }
     } 
}

Assume that any required variables are declared and no programming-related errors.

I know the first lines finds the distance of the current point from the origin. The second line finds the distance of the next point from the origin. If the first point is further away than the second, the first if statement is executed, otherwise the second if statement. Now what I can't understand is what's happening inside the if statements. It looks the the magnitude is being calculated but what does multiplying by depth2 and dividing by depth1 correspond to? Likewise in the second if statement, the point is now multiplied by depth1 and divided by depth2.

1

There are 1 best solutions below

6
On BEST ANSWER

See the points i and i+1 as belonging to spheres of respective radii depth1 and depth2. Then the diff components corresponds to the vector that joins the radial projections of the two points on the smallest sphere (one of the points is already on this sphere).

Then the test compares the distance between these projections to a threshold. But the distance formula is modified in that the z difference is weighted in an unusual way, as if z was divided by the square root of the smallest radius.

This expression does not make much mathematical sense and is dimensionally incorrect. With a fixed placement of the parenthesis, the test would mean "closer than a tenth of the radius".