Floating Point Coordinate Tolerances


#1

I am working on a python script that shatters a bunch of overlapping, gathers all the end points and builds node network for a Djikstra’s path mapping algorithm. The biggest problem I am having right now is how to determine if points are “equal”. Right now, when the overlapping lines get shattered, their overlapping ends might have slightly different endpoints. This difference is 10-11 decimal points to the right so is incredibly minute.

What is the best way to identify “same/similar” points?

Thanks


#2

One way is to subtract the coordinates, take the absolute value of the result and check if it’s less than your required tolerance. If so, the points can be considered to be “identical” within tolerance. You can use a short-circuit logic to make it go quicker.

In Python, you can also simply subtract the 3dpoint objects, it will return a vector, which you can check the magnitude of and see if it’s less than tolerance.

There is a Rhinoscriptsyntax method “PointCompare” but with very large numbers of points it might be slow. There is also a method CullDuplicatePoints if you have all the points in a list and only want unique points. Both methods allow a user-set tolerance as an argument.

I don’t know which is the fastest of all the above methods…

–Mitch


(Steve Baer) #3

There is also the EpsilonEquals function on Point3d that may be what you need (thanks to @menno for adding this)

import rhinoscriptsyntax as rs

pt1 = rs.coerce3dpoint((0,0,1))
pt2 = rs.coerce3dpoint((0,0,1.001))
print pt1.EpsilonEquals(pt2,0.01)

(Menno Deij - van Rijswijk) #4

The EpsilonEquals method will check each element for equality within the given tolerance; the method of @Helvetosaur checks the square root of the sum of the elements squared (i.e. vector length - see http://en.wikipedia.org/wiki/Euclidean_vector#Length)

Probably just nit-picking, but they are not exactly similar.