What is the term for the calculation of the closest distance between a point and an object?

What is the term for the calculation of the closest distance between a point and an object?

Instead of closest point to brep in C# I want to know how to calculate it myself.

ClosestDistance ?

// Rolf

1 Like

Thank you. But is there a certain specific name of a kind of calculation?

I mean, if you want to calculate the distance between a point an an object without the ‘closest point to brep,’ how is it calculated manually :thinking:

How is Brep.ClosestPoint written?
There is a manual or sourcecode somewhere I thought but I cannot find it.

For some special types of objects including straight lines, planes, spheres, constant diameter circular cylinders there are mathematical methods for ditectly calculating the shortest distance between an object and a point. The details of the methods will be different for each type of object.

For general objects the shortest distance to a point may have to be calculated iteratively with many different methods possible for doing the calculations.

1 Like

:upside_down_face: :upside_down_face: :upside_down_face: :upside_down_face: :slightly_smiling_face: :upside_down_face: :slightly_smiling_face:

Do you might know where to find the sourcecode of Rhino.Geometry?

It can be this for a rectangle

function distance(rect, p) {
  var dx = Math.max(rect.min.x - p.x, 0, p.x - rect.max.x);
  var dy = Math.max(rect.min.y - p.y, 0, p.y - rect.max.y);
  return Math.sqrt(dx*dx + dy*dy);

But what could it be for the other geometry types :thinking:

If it were open source you wouldn’t have to pay for a license. In short, there is no such code to be found (for Rhino).

For the distance to a Brep, my best advice would be to look into other (open source) geometry libraries to find a strategy that works.

// Rolf

1 Like

Thank you @RIL :smiley: and @davidcockey :smiley:
Now I understand it :smiley:

To calculate the distance between a Rectangle3d and a Point3d, the following is NOT the right formula.

  double distance (Rectangle3d rect, Point3d p){
    //var dx = Math.Max(rect.X.Min - p.X, 0, p.X - rect.X.Max);
    //var dy = Math.Max(rect.Y.Min - p.Y, 0, p.Y - rect.Y.Max);
    var dx = Math.Max(rect.X.Min - p.X, p.X - rect.X.Max);
    var dy = Math.Max(rect.Y.Min - p.Y, p.Y - rect.Y.Max);
    return Math.Sqrt(dx * dx + dy * dy);

I expect I will bump more often against these kind of problems.

Is there a more specific name for ‘mathematical methods’ within this theme of calculating distances between a point and a circle, box, rectangle et cetera you might know of :thinking::slight_smile:

First you need a strategy (for each case). Then you apply some math which solves your strategy.

There’s no given “algorithm” which provides a strategy (which strategy?). A strategy picks the math/algorithm(s) which solves the problem.

Google is your friend. Or DuckDuckGo. Search for the problem and you’ll find different strategies using different algorithms to solve the problem(s).

// Rolf

1 Like

In the aerospace industry this is called the “directed distance”, meaning the distance from the point in space to the surface as measured along a specific vector direction. In general directed distances are used to calculate the location and direction of a milling machine cutter as it moves across a piece of metal to cut out the required shape.

Originally there were a number of repetitive algorithms to calculate the directed distance. These codes used iterative methods like Newton-Raphson, binary division, least squares distance, etc. But for large parts and high precision these tended to fail for various reasons, primarily roundoff and truncation errors.

The solution was to use 2nd order partial differential equations to calculate the direction and distance directly, without any iteration. This can only be done if there is a concise way to calculate things like radius of curvature and surface normals for the surface. I don’t know if this is possible for a Nurbs surface, but probably it is. Figuring out the required differential equations is the tricky part of course; although I did it once upon a time, for me that time is long gone.

1 Like