Ellipses intersections

Ellipses intersections

dinocoglitore
Advocate Advocate
642 Views
2 Replies
Message 1 of 3

Ellipses intersections

dinocoglitore
Advocate
Advocate

 

Hello, I am trying to find the coordinates of the intersection points between two ellipses, that are in different sketches, as you can see in the picture:

 

punti_intersezione.png

I used an example found in a forum post: 

# -*- coding: utf-8 -*-
"""
Created on Mon Sep 19 16:53:42 2016

@author: DINODESK
"""

import adsk.core, adsk.fusion, traceback, math

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        design = adsk.fusion.Design.cast(app.activeProduct)

        sketch1 = design.rootComponent.sketches.item(0)
        sketch2 = design.rootComponent.sketches.item(1)
        
        # collection of points
        sketchPoints2 = sketch2.sketchPoints
        
        coll1 = adsk.core.ObjectCollection.create()
        for curve in sketch1.sketchCurves:
            coll1.add(curve)
       
        coll2 = adsk.core.ObjectCollection.create()
        for curve in sketch2.sketchCurves:
            coll2.add(curve)

        projectedcurves = adsk.core.ObjectCollection.create()
        for curve in sketch1.sketchCurves:
            results = sketch2.project(curve)
            for resultcurve in results:
                projectedcurves.add(resultcurve)

        intersectedsplines = adsk.core.ObjectCollection.create()
        for curve in projectedcurves:
            result, intersectionresults, intersectionpts = curve.intersections(coll1)
            if result:
                for intersectionresult in intersectionresults:
                    intersectedsplines.add(intersectionresult)

        for i in range(0,intersectionpts.count):                    
            sketchPoints2.add(intersectionpts.item(i))            
   except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
                

but the result is not what I exspected. This is what happen:

 

punti_intersezione_sbagliati.png

 

There is someone who can give me a hint or some code examples.

Thanks

Dino

0 Likes
Accepted solutions (1)
643 Views
2 Replies
Replies (2)
Message 2 of 3

ekinsb
Alumni
Alumni
Accepted solution

The sample you are using gets all of the curves in a sketch, which also includes the lines that are along the major and minor axes.  I also found that as long as you don't need to create constraints to define the position of the points that you don't need to project the second ellipse into the first sketch.  I don't know if you care about the associativity or not.  If you do, then you will need to copy the ellipse and also create two coincident constraints for each point; one between the point and each ellipse.  Below is my test code that gets the intersection coordinates and creates sketch points at those locations without any constraints to the ellipses.

 

def ellipseIntersect():
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        design = adsk.fusion.Design.cast(app.activeProduct)

        sketch1 = design.rootComponent.sketches.item(0)
        sketch2 = design.rootComponent.sketches.item(1)
        
        sk1Ellipse = sketch1.sketchCurves.sketchEllipses.item(0)
        
        sk2Ellipse = sketch2.sketchCurves.sketchEllipses.item(0)
        sk2EllipseCol = adsk.core.ObjectCollection.create()
        sk2EllipseCol.add(sk2Ellipse)
    
        (result, intersectionResults, intersectionPts) = sk1Ellipse.intersections(sk2EllipseCol)

        skPnts = sketch1.sketchPoints
        for pnt in intersectionPts:
            skPnts.add(pnt)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3

dinocoglitore
Advocate
Advocate

Hi Brian, I thank yor very much for the immediate answer.

It is the solution I was looking for.

I have to learn a lot and your lessons are what I need !

 

punti_intersezione_risolto.png

 

Many Thanks, Dino

0 Likes