Radius of tangent circle cannot be set properly

Radius of tangent circle cannot be set properly

marcinszydlowski.1984
Enthusiast Enthusiast
2,085 Views
5 Replies
Message 1 of 6

Radius of tangent circle cannot be set properly

marcinszydlowski.1984
Enthusiast
Enthusiast

Hello,

 

I have a problem with proper setting radius of circle when:

  1. circle is tangent to arcs
  2. Z coordinate of those arcs and circle is different than 0

I checked it for lines and then it works. I use newest version of Fusion for Windows, monthly subscription.

Code:

import adsk.core, adsk.fusion

def run(context):
    app = adsk.core.Application.get()
    product = app.activeProduct
    design = adsk.fusion.Design.cast(product)
    rootComponent = design.rootComponent
    design.designType = adsk.fusion.DesignTypes.DirectDesignType

    sketch = rootComponent.sketches.add(rootComponent.xYConstructionPlane)

    # Lines - z=0   OK, radius of circle is 1
    z = 0
    p11 = adsk.core.Point3D.create(2, 1, z)
    p12 = adsk.core.Point3D.create(5, 1.5, z)
    p21 = adsk.core.Point3D.create(1, 1, z)
    p22 = adsk.core.Point3D.create(2.6, 6, z)

    line1 = sketch.sketchCurves.sketchLines.addByTwoPoints(p11, p12)
    line2 = sketch.sketchCurves.sketchLines.addByTwoPoints(p21, p22)

    circle1 = sketch.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(4, 4, z), 1)

    # Make circle tangent to lines
    line1.isFixed = True
    line2.isFixed = True
    sketch.geometricConstraints.addTangent(circle1, line1)
    sketch.geometricConstraints.addTangent(circle1, line2)

    # Lines - z=5   OK, radius of circle is 1
    z = 5
    p11 = adsk.core.Point3D.create(2, 1, z)
    p12 = adsk.core.Point3D.create(5, 1.5, z)
    p21 = adsk.core.Point3D.create(1, 1, z)
    p22 = adsk.core.Point3D.create(2.6, 6, z)

    line1 = sketch.sketchCurves.sketchLines.addByTwoPoints(p11, p12)
    line2 = sketch.sketchCurves.sketchLines.addByTwoPoints(p21, p22)

    circle1 = sketch.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(4, 4, z), 1)

    # Make circle tangent to lines
    line1.isFixed = True
    line2.isFixed = True
    sketch.geometricConstraints.addTangent(circle1, line1)
    sketch.geometricConstraints.addTangent(circle1, line2)

    # Arcs - z=0   OK, radius of circle is 1
    z = 0
    p1s = adsk.core.Point3D.create(12, 1, z)
    p1e = adsk.core.Point3D.create(15, 1.5, z)
    p1m = adsk.core.Point3D.create(13.5, 1.4, z)
    p2s = adsk.core.Point3D.create(11, 1, z)
    p2e = adsk.core.Point3D.create(12.6, 6, z)
    p2m = adsk.core.Point3D.create(11.5, 3.8, z)

    p1sSketch = sketch.sketchPoints.add(p1s)
    p1eSketch = sketch.sketchPoints.add(p1e)
    arc1 = sketch.sketchCurves.sketchArcs.addByThreePoints(p1sSketch, p1m, p1eSketch)
    p2sSketch = sketch.sketchPoints.add(p2s)
    p2eSketch = sketch.sketchPoints.add(p2e)
    arc2 = sketch.sketchCurves.sketchArcs.addByThreePoints(p2sSketch, p2m, p2eSketch)

    circle2 = sketch.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(14, 4, z), 1)
    arc1.isFixed = True
    arc2.isFixed = True
    sketch.geometricConstraints.addTangent(circle2, arc1)
    sketch.geometricConstraints.addTangent(circle2, arc2)
    circle2.radius = 1

    # Arcs - z=5   WRONG, radius of circle is not 1
    z = 5
    p1s = adsk.core.Point3D.create(12, 1, z)
    p1e = adsk.core.Point3D.create(15, 1.5, z)
    p1m = adsk.core.Point3D.create(13.5, 1.4, z)
    p2s = adsk.core.Point3D.create(11, 1, z)
    p2e = adsk.core.Point3D.create(12.6, 6, z)
    p2m = adsk.core.Point3D.create(11.5, 3.8, z)

    p1sSketch = sketch.sketchPoints.add(p1s)
    p1eSketch = sketch.sketchPoints.add(p1e)
    arc1 = sketch.sketchCurves.sketchArcs.addByThreePoints(p1sSketch, p1m, p1eSketch)
    p2sSketch = sketch.sketchPoints.add(p2s)
    p2eSketch = sketch.sketchPoints.add(p2e)
    arc2 = sketch.sketchCurves.sketchArcs.addByThreePoints(p2sSketch, p2m, p2eSketch)

    circle2 = sketch.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(14, 4, z), 1)
    arc1.isFixed = True
    arc2.isFixed = True
    sketch.geometricConstraints.addTangent(circle2, arc1)
    sketch.geometricConstraints.addTangent(circle2, arc2)
    circle2.radius = 1

 

0 Likes
Accepted solutions (2)
2,086 Views
5 Replies
Replies (5)
Message 2 of 6

BrianEkins
Mentor
Mentor
Accepted solution

I tried running your code and it runs without any errors but I don't know if the result is what you expect.  What is the specific problem?  One thing I would be cautious of is drawing things of the X-Y sketch plane and expecting constraints to behave like normal.  In the UI you're limited to what you can do with curves that aren't on the X-Y sketch plane.  For example, I can't add a dimension constraint to the circles.  You would be better off having to sketches, one for each Z height.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 6

marcinszydlowski.1984
Enthusiast
Enthusiast

Hi Brian,

 

the problem is that circle2.radius = 1 in the fourth example:

 

...
    # Arcs - z=5   WRONG, radius of circle is not 1
    z = 5
    p1s = adsk.core.Point3D.create(12, 1, z)
    p1e = adsk.core.Point3D.create(15, 1.5, z)
    p1m = adsk.core.Point3D.create(13.5, 1.4, z)
    p2s = adsk.core.Point3D.create(11, 1, z)
    p2e = adsk.core.Point3D.create(12.6, 6, z)
    p2m = adsk.core.Point3D.create(11.5, 3.8, z)

    p1sSketch = sketch.sketchPoints.add(p1s)
    p1eSketch = sketch.sketchPoints.add(p1e)
    arc1 = sketch.sketchCurves.sketchArcs.addByThreePoints(p1sSketch, p1m, p1eSketch)
    p2sSketch = sketch.sketchPoints.add(p2s)
    p2eSketch = sketch.sketchPoints.add(p2e)
    arc2 = sketch.sketchCurves.sketchArcs.addByThreePoints(p2sSketch, p2m, p2eSketch)

    circle2 = sketch.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(14, 4, z), 1)
    arc1.isFixed = True
    arc2.isFixed = True
    sketch.geometricConstraints.addTangent(circle2, arc1)
    sketch.geometricConstraints.addTangent(circle2, arc2)
    circle2.radius = 1

 

 

doesn't work for arcs on z = 5 but similar code works for lines (second example):

...
# Lines - z=5   OK, radius of circle is 1
...


I changed radius of circle in the second example after applying constraints and it works.

But it doesn't when I use arcs:

All examples visibleAll examples visibleView from top (along Z axis)View from top (along Z axis)

 

My target is to set all radiuses equals in one sketch. I can use many sketches but without direct design it'll expand timeline significantly and slow down Fusion. I cannot use sweep in this case. I also tried parametric design with adding radial dimension (as driving) to the circle but it didn't help. 

I want to know if I do something wrong or it is specific behaviour for constraints with arcs and I have to do workaround for it.

0 Likes
Message 4 of 6

marcinszydlowski.1984
Enthusiast
Enthusiast

If it's not a bug, please close this. I've handled this using cosines theorem which is enough for my case.

0 Likes
Message 5 of 6

marcinszydlowski.1984
Enthusiast
Enthusiast
Accepted solution

Ok. As a quick workaround for this particular case I used law of cosines. I always need one case  (two intersection points of circles and third circle inside the second one) so formula will be always the same. Another assumption is that circles/arcs are intersect together in two points.

For those of you who have similar problem with proper radius between three tangent circles/arcs on coordinate Z different than 0 here's the idea and solution.

We need to find the center of red circle for given radiusWe need to find the center of red circle for given radius

Symbols:

  • O1 - known center of circle/arc 1
  • O2 - known center of circle/arc 2
  • r1 - known radius of circle/arc 1
  • r2 - known radius of circle/arc 2
  • r3 - desired radius of circle/arc 3
  • d - known distance between centers of circles/arcs 1 and 2
  • r1 + r3 - known distance between centers of circles/arcs 1 and 3
  • r2 - r3 - known distance between centers of circles/arcs 2 and 3
  • alpha - angle between vectors d and r1r3
  • betha - angle between vector [1, 0, 0] and r1r3
  • O3 - unknown center of circle/arc 3

The idea is to find center of circle 3 based on distance r1 + r3 and angle alpha + betha.

 

Cosine theorem for triangle O1 O2 O3 is:

Cosine formula for triangle O1 O2 O3Cosine formula for triangle O1 O2 O3

By transforming this we can obtain alpha angle:

Alpha angleAlpha angle

This is all we need. All script showing an example is listed below.

import math
import adsk.core, adsk.fusion

def run(context):
    app = adsk.core.Application.get()
    product = app.activeProduct
    design = adsk.fusion.Design.cast(product)
    rootComp = design.rootComponent

    # Assumption that circle 3 is inside circle 2 and near the top intersection point of circles 1 and 2
    z = 3

    # Circle 1
    radius1 = 3.1
    center1 = adsk.core.Point3D.create(-1, 0.5, z)

    # Circle 2
    radius2 = 2.03
    center2 = adsk.core.Point3D.create(3.5, 1.2, z)

    # Draw circle 1 and 2
    sketch = rootComp.sketches.add(rootComp.xYConstructionPlane)
    sketch.sketchCurves.sketchCircles.addByCenterRadius(center1, radius1)
    sketch.sketchCurves.sketchCircles.addByCenterRadius(center2, radius2)

    # Show wait
    adsk.core.Application.get().userInterface.messageBox("Click to continue...", "Waiting")

    # Circle 3
    radius3 = 0.9

    # Calculations
    d = center1.distanceTo(center2)
    r1r3 = radius1 + radius3
    r2r3 = radius2 - radius3
    alpha = math.acos((r2r3**2 - r1r3**2 - d**2) / (-2 * r1r3 * d))
    betha = center1.vectorTo(center2).angleTo(adsk.core.Vector3D.create(1, 0, 0))
    center3x = center1.x + r1r3 * math.cos(alpha + betha)
    center3y = center1.y + r1r3 * math.sin(alpha + betha)
    center3 = adsk.core.Point3D.create(center3x, center3y, z)
    sketch.sketchCurves.sketchCircles.addByCenterRadius(center3, radius3)

 

Formulas for other cases (outside circles, other intersection point, different direction) will be slightly different but idea is the same. The only differences will be with signs +/-. You have to remember that for non-intersecting circles/arcs it'll raise cosine domain error so you need to change approach.

0 Likes
Message 6 of 6

marcinszydlowski.1984
Enthusiast
Enthusiast

Thank you @BrianEkins for the tip. It seems that keeping profiles or other important features per sketch is the best solution so far.

0 Likes