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.