-1

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.

user1420
  • 165
  • 1
  • 1
  • 8
  • Would be better to tell us the context instead of letting us guess. –  May 29 '17 at 09:03
  • Are you sure it is "sqrt(diffX * diffX + diffYdiffY + diffZ diffZ/depth2)" instead of "sqrt(diffX * diffX + diffYdiffY + diffZ diffZ)/depth2" ??? – achille hui May 29 '17 at 09:08
  • @achillehui: yep, this is more than probably a bug/typo in the code. "assume no programming-related errors" is hard to believe. –  May 29 '17 at 09:12
  • my apologies! There is a typo on my part! Yes, I missed the closing bracket for the sqrt function. I have fixed it in the edit @YvesDaoust, the only context I have is that of 3D coordinate processing. There are no comments or documentation to go along with the program – user1420 May 29 '17 at 09:30
  • @user1420: I can't believe that you don't known what this program is used for. –  May 29 '17 at 09:32
  • @YvesDaoust, its for 3D Point Cloud Processing. I'm guessing there is some filtering going on. Believe me I am fully aware of how straightforward it will be to say this program implements algorithm X but I do not know that. – user1420 May 29 '17 at 09:35
  • Then the "something happens" sections will tell more. Probably the points are considered as significantly close so that you discard or keep them or something similar. As the loop is a simple one, this seems to be dealing with a 3D curve. –  May 29 '17 at 09:38
  • I have added that section. But I do not know what its indicates. Probably a flag to keep track of neighboring points. But my worry is not that, I'm more interested in the lines before that – user1420 May 29 '17 at 09:44
  • @user1420: I have answered that. –  May 29 '17 at 12:08

1 Answers1

0

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".

  • Does your answer still hold true after I added the missing bracket? – user1420 May 29 '17 at 10:00
  • @user1420: I don'tthink you understood my third paragraph. –  May 29 '17 at 12:10
  • Sorry. Given that you gave this answer before I made that edit, I thought of reconfirming. Thanks for your answer. Just one more question. Can you give me a list of keywords that I can use to search for more math-related information related to second sentence of paragraph 1? I have trouble visualizing it. Searching for "3D radial projection" didn't help. – user1420 May 30 '17 at 00:51
  • @user1420 https://blogs.scientificamerican.com/observations/mathematicians-at-play-3-d-puzzl/, third picture. –  May 30 '17 at 06:45
  • Would you mind referring me to some sources where I can see and read more about the equations used? While I was able to see the third picture in the link, I was not able to find equations related to it. Thanks in advance – user1420 Jun 22 '17 at 02:04
  • @user1420: $\vec r\to\vec r/|\vec r|$. –  Jun 22 '17 at 14:56