Is the Curve.GetDistancesBetweenCurves method buggy?

Could someone clearify why the Curve.GetDistance BetweenCurves Method isn’t succeeded in this case? Whereas the Curve Proximity component is successful


Distance.gh (4.7 KB)

Hello
I have the same errors also in C#, also in Rhino 6. It seems to be a bug.

1 Like

I don’t know why that doesn’t simply make the distance between them zero, but your curves appear to intersect. What happens when you use it on the two rul s? Are you supposed to test for intersection first with .PlanarCurveCollision?

Return Value

Type: Boolean
true if the operation succeeded; otherwise false.

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Curve_GetDistancesBetweenCurves.htm

1 Like

“rul” curves and “Crv” curve aren’t coplanar and Curve.GetDistance BetweenCurves method should work for non-coplanar curves as well.

I’d like to find the parameters on the “Crv” where “rul” curves touch “Crv”

I bet the Grasshopper component implements Curve.ClosestPoints. See an example file here:

Also, if your geometries are all lines maybe have a read through the entire topic above.

Edit: I see I forgot to upload the file in the linked post, but there’s a screenshot :melting_face:

1 Like

Yes, Thank you! The Curve.ClosestPoints method is fruitful, it solves the issue! But the Curve.GetDistanceBetweenCurves method gives curves parametes directly, if it would work. Will use it

1 Like

Looks like this method only works when the curves share a somewhat common direction. I made a ticket for the developer: RH-73988 RhinoCommon SDK: Curve.GetDistancesBetweenCurves method does not work if curves do not share a similar direction

1 Like

Hi @sadovshikov,

Although the comments do not indicate this, the Curve.GetDistancesBetweenCurves method is primarily used for computing curve deviation.

In most cases, you’re better off using Curve.ClosestPoints.

– Dale

3 Likes

RH-73988 is fixed in Rhino 7 Service Release 29 Release Candidate

1 Like

It doesn’t work in this case as well. Is it the same problem?


GetDistancesBetweenCurves.gh (3.8 KB)

@sadovshikov I don’t see an geometry in your .gh file. Are the curves in the same orientation?

Generally it sounds like this method was written for comparing curves that are very similar to one another (including similar parametrizations and orientations) and in the same location; for example this would be used to compare the output of a rebuild operation to its initial curve.

What are you trying to achieve with this method? Finding the closest point between two curves is a well defined operation that is better solved with the curve ClosestPoints method. Finding the maximum distance between two curves could have different definitions, and GetDistancesBetweenCurves takes a simple approach to that (finding two locally far away locations on the curves, starting from similar parameter values). A more general definition would be something like:


with D_1 and D_2 the domain of the curves C_1 and C_2, and d the distance measure.

I don’t think we have that second definition available in the SDK, despite what the name of GetDistancesBetweenCurves might imply.

1 Like

Yes, I’d like to detect the maximum distance between these two curves.

How do you define the maximum distance between two curves? For the two black lines below, would the maximum distance be the green line (what I think GetDistancesBetweenCurves is doing), the red line (the max(min(dist())) expression above), or the blue line (maximum distance between any two points on the curves)?

If the red distance is the one you are after, is it important that this distance is symmetrical? The way I wrote my equation above, the distance from C_1 to C_2 is not always the same as the distance from C_2 to C_1.

So I’ll ask my question again, because without the answer to this I cannot help you with an algorithm in Rhino, what are you trying to achieve with this method? What will you do with your “maximum distance” value, and how do you define it?

1 Like

Yeah, that’s always the question. The absolute answer is the blue line, but most often people want the green, which I interpret as the maximum of a series of distances to closest points sampled along the curve…. i.e. the maximum of a series of minimums.

That would be the red one I think. The green one is not the result of a closest-point sampling (at least if you sample on the left-hand side curve and find closest points to these samples on the right-hand side curve), so it cannot be a max of closest points.

“Maximum distance” between objects is really ill-defined, so I need to understand which definition we are after here if I want to do anything about making that available in Rhino.

Thank you for your reply! I’m sorry for the ambiguous question. So, for my precise purpose, I am looking for the spot on a curve that has the maximum distance to another curve in the case when both curves are identical, but one of the curves is rotated along the common axis. For the “maximum distance” I imply the red line option you have described above (i.e. maximum of a series of minimums distances).

Please take a look at the following examples where I have located a spot on the curve with a rough approximation of the maximum distance:

In the first example, the red and green lines will be the same line:

In the second they will be different:


MaxDist.gh (11.7 KB)

Thanks for the additional details!

I tried a few things because I thought your special case (rotating a curve and finding some distance between the two copies) would simplify the problem, but nothing worked out. Your method is the most straight-forward to solve this, the next step to get a better result is to run an optimizer on the best guess you found, to find a better local maximum around that point.

I made a YouTrack item to request this functionality to be added to Rhino RH-74708 Computing a maximum distance between two curves

1 Like

Here is an interesting example.
Vornoi.3dm (67.8 KB)
image
The maximum distance between the purple line and the parabolic curve is shown. It’s not at a critical point of the distance function d(s,t) = || A(s) - B(t) || but is at the intersection of the Vornoi diagram of the curve and the line.

1 Like