Best Way to Test if 2 points are coincident?

Best Way to Test if 2 points are coincident?

dirktheeng
Advocate Advocate
854 Views
3 Replies
Message 1 of 4

Best Way to Test if 2 points are coincident?

dirktheeng
Advocate
Advocate

So, I need to test if 2 sketchPoints lay on top of eachother in a sketch.  Say the sketch points are sp1 and sp2

 

First, I make a point 3d object

 

p1 = sp1.geometry

 

p2 = sp2.geometry

 

Then compare the cooridnates

 

is |p1.x - p2.x| < smallNumber and |p1.y - p2.y| < smallNumber

 

The question is how small does small number have to be?  Or is there an entirely better way of doing this?

21st Century Woodworking

-Blending 21st Century Woodworking with Old World Skill
0 Likes
Accepted solutions (1)
855 Views
3 Replies
Replies (3)
Message 2 of 4

KrisKaplan
Autodesk
Autodesk
Accepted solution

The easiest way to do this would be to use Point3D's isEqualTo method.

 

equal = sp1.geometry.isEqualTo(sp2.geometry)

This will use the modeler's default system tolerance (which is 1e-6).  This is the tolerance that we would use to test for any general point equality.  If you want to use some other tolerance, you can use the distanceTo method.

 

equal = sp1.geometry.distanceTo(sp2.geometry) <= myTol

 

Kris



Kris Kaplan
Message 3 of 4

Anonymous
Not applicable

I try the following coding ,but this is error

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)

        root = design.rootComponent
        sketches = root.sketches
        sketch = sketches.add(root.xYConstructionPlane)
        sketchPoints = sketch.sketchPoints
        a1 = adsk.core.Point3D.create(1, 1, 1)
        a2 = adsk.core.Point3D.create(0, 3, 0)
        sketchPoint1 = sketchPoints.add(a1)
        sketchPoint2 = sketchPoints.add(a2)
        sp1 = sketchPoint1.geometry
        sp2 = sketchPoint2.geometry
        equal = sp1.geometry.isEqualTo(sp2.geometry)
        print (equal)
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

WX20190613-104352@2x.png

could you tell me why, and how to improve it 

0 Likes
Message 4 of 4

BrianEkins
Mentor
Mentor

The reason for the failure is that you're getting the Point3D object from the sketch point using the geometry property an assigning it so sp1 and sp2 and then in the following line you're trying to call the geometry property on sp1 and sp2 but they're Point3D objects and don't have a geometry property.  Just change this line:

equal = sp1.geometry.isEqualTo(sp2.geometry)

to this:

equal = sp1.isEqualTo(sp2)
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com