Extract arc from circle at segment length 12 m

Hi everybody

I’m Traying to extract an arc with 12 m length from a circle but python give me the outer arc although I reverse the arc Start and End point…so what’s wrong in my code??

Here my code:

import sys
import clr
import math
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#Circle inputs
circle = IN[0]
offset_distance = IN[1]
overlap_length = 1

# Circle's center point
Center_point = circle.CenterPoint
Start_pt1 = circle.StartPoint
End_pt1 = circle.PointAtSegmentLength(12)
arc = Arc.ByCenterPointStartPointEndPoint(Center_point, Start_pt1, End_pt1)
Radius = Line.ByStartPointEndPoint(Start_pt1, Center_point)
def isclockwise(arc):
    vecta = Vector.ByTwoPoints(Center_point, Start_pt1)
    vectb = Vector.ByTwoPoints(Center_point, End_pt1)
    cp = vecta.Cross(vectb)
    return cp.Z < 0

def fix_arc(arc):
    if isclockwise(arc):
        return arc.Reverse()
    else:
       return arc
# vector to offset circles inwards by offset_distance
offset_vector = Radius.Direction.Normalized()
Normal_vector = Vector.ByCoordinates(0, 0, 1)
lst = [circle]
arc = fix_arc(arc)

        
OUT = Start_pt1, End_pt1, arc.Length

Thanks.

The normal of the circle determines the direction of the curve and your arc segment, as you suspected. However, arc.Reverse() just inverts the direction of the curve, which has already been created at this point. Instead, you need to check isclockwise() to determine the order of the start and end points for the arc. If the vectors would result in a counterclockwise direction, you need to flip their order so you get a clockwise arc - and therefore the correct length.

2 Likes

hello, your indentation in your function (fix arc) doesn’t seem to be aligned
Cordially
christian.stan

1 Like

Hello,
need to fix clockwise the input circle first (not the arc)

import sys
import clr
import math
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#Circle inputs
circle = IN[0]
offset_distance = IN[1]
overlap_length = 1

def isclockwise(circular_curve):
    Center_point = circular_curve.CenterPoint
    Start_pt1 = circular_curve.StartPoint
    End_pt1 = circular_curve.PointAtParameter(0.95)
    vecta = Vector.ByTwoPoints(Center_point, Start_pt1)
    vectb = Vector.ByTwoPoints(Center_point, End_pt1)
    cp = vecta.Cross(vectb)
    return cp.Z < 0

def fix_arc(circular_curve):
    if isclockwise(circular_curve):
        return circular_curve
    else:
        return circular_curve.Reverse()

circle = fix_arc(circle)
# Circle's center point
End_pt1 = circle.PointAtSegmentLength(12)
arc = Arc.ByCenterPointStartPointEndPoint(circle.CenterPoint, circle.StartPoint, End_pt1)
        
OUT = arc.Length, arc
3 Likes

@Nick_Boyts , @christian.stan

I tried few options to fix my problem…but no result (I found that the direction of rotation of my imported geometry is the opposite direction of rotation in dynamo which is counterclockwise and an offset angle of 90 degrees between the start point of the imported geometry and a same geometry created in dynamo !! )
I was able to fix the start point at the positif X Axis, but I can’t fix the second point correctly which corresponds to the point at segment length (12m)
I noticed too that Y coordinate of the start point is not equal to0 and that is strange!! (is there an explanation)??

here my code:

arc
import sys
import clr
import math
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#Circle inputs
circle = IN[0]
offset_distance = IN[1]
overlap_length = 1

# Circle's center point
Center_point = circle.CenterPoint
Normal_vector = Vector.ByCoordinates(0, 0, 1)
Start_pt1 = circle.PointAtParameter(0)
End_pt1 = circle.PointAtSegmentLength(12)
arc = Arc.ByCenterPointStartPointEndPoint(Center_point, Start_pt1, End_pt1)
Start_Angle = arc.StartAngle
Radius = Line.ByStartPointEndPoint(Start_pt1, Center_point)
def Start_Point(circle):
    if Start_Angle == 0:
        return arc
    else:
        Start_pt1 = circle.PointAtParameter(0.5)
        return Start_pt1

Start_pt1= Start_Point(circle)
circle = circle.Rotate(Center_point, Normal_vector.Reverse(), 90)
End_pt1 = circle.PointAtSegmentLength(12)
arc = Arc.ByCenterPointStartPointEndPoint(Center_point, Start_pt1, End_pt1)

   
OUT = arc.StartPoint, arc.EndPoint, arc.Length

Thanks.

You’re overcomplicating it now. As I mentioned, and as @c.poupin has shown, you just need to maintain a positive direction in the arc or circle direction. Either flip the circle before drawing the arc or flip the start/end points of the arc when drawing (as necessary).

@Nick_Boyts

I was typing my reply and I’ve not see @c.poupin post at that moment !!
It’s clear to me now how to change the direction of the circle… although I wanted the arc start point to be in the positive x-axis but it’s in the negative x-axis… I’ll try to fix it

Thanks.

Reversing the direction shouldn’t change the start/end points so that’s more of an issue with the orientation of the circle itself. You can get around this by rotating back to 0 (x-axis) or by creating new start/end points based on an x-axis intersection.

1 Like