Distance between two mesh not working?

My playground:


I would like to draw a disc centered on leftmost sphere and tangent to rightmost sphere, but whatever I tried failed while trying to calculate spheres distance:

  • sphereL.position.subtract(sphereHand.position).length()
  • sphereL.getAbsolutePosition().subtract(sphereHand.getAbsolutePosition()).length()
  • by math:
 xdist = SHOULDER_LENGTH*Math.sin(ang1) - FOREARM_LENGTH*Math.sin(ang2);
    ydist = -SHOULDER_LENGTH*Math.cos(ang1)  + FOREARM_LENGTH*Math.sin(ang1) - UPPERARM_LENGTH*Math.cos(ang1);
    handDistance = Math.sqrt(Math.pow(xdist,2) + Math.pow(ydist,2));// * Math.cos(ang2);

Any idea?

Version #2 should work, but note that you may have to call sphereL.computeWorldMatrix(true); sphereHand.computeWorldMatrix(true); to make sure getAbsolutePosition will return the right value.

1 Like