2 Replies Latest reply on Jan 8, 2016 5:07 PM by Elisha Stevenson

    Solidworks Calculates Zero Distance Between Point and Edge

    Elisha Stevenson

      I'm noticing some strange behavior when working with corners of certain geometries. In the above image, the highlighted point and highlighted edge are considered coincident by SolidWorks. If the edge was extended, this would be true, but in this instance the to entities are only collinear and do not actually coincide.

      I didn't realize this was happening until I got some unexpected results from the below code.


                              closestPointOnEdge = (double[])((Edge)edgeEntity).GetClosestPointOn(pointPosition.X, pointPosition.Y, pointPosition.Z);


                              currentDistanceFromEdge = Distance(closestPointOnEdge, pointPosition)


      The currentDistanceFromEdge is calculated as zero. Graphically, it isn't on the line. If I add another relation to make the edge endpoint and the point coincident, then the point moves in position, so I'm pretty certain rendering isn't the problem. When I add a smart dimension to the endpoint and the point i get a distance of "0.00000508m." I've worked around corners in larger geometries, so I'm fairly certain the small resolution of the example isn't the problem.

        • Re: Solidworks Calculates Zero Distance Between Point and Edge
          Matt Martens

          The reason is your point is actually on this edge in sketch space. API has locations of every entity in two different ways while in sketch mode, sketch position and absolute position. Think of it as the position based on the origin of the active sketch and the position based on the actual origin.


          Based on the image you have shown, you are currently in sketch mode. This means the API is determining the location of the edge and the point in the 2D plane of the active sketch. Because you have a coincident relation between the two they isn't any distance between the two. In a sketch an edge is treated the same as a line. That's why when you have a coincident relation you can still move a point passed the end of the edge.