Center of a circular arc

anyone here can help me,
I am trying to get the centre point position of a 3-point arc in 3d space.
but I am really bad with vector math.
I google for a long time, but no luck.
Screenshot 2022-06-28 215644

Are you trying to solve the math, or just find the point?

There is a built-in 3 point arc tool in Maya. Create arcs | Maya 2020 | Autodesk Knowledge Network

Create → Curve Tools → Three Point Circular Arc

hi clesage, I am trying to solve the math,
I can get the point I want with Three-Point Circular Arc,
but I want to make a script without select points manually,
the problem I have currently I can create node and create arc without any problem,
but it just won’t give me the centre point of the circular arc.
the pivot point will only stay at 0,0,0

Cool, just checking since you said you were bad at math and found nothing in google.

All the same though, when you create a makeThreePointCircularArc node, it certainly does have an output .center that you can query.

(Oddly, if you connect a transform to it, it doesn’t update automatically when the 3 points are modified. But you can force it to refresh by force reconnecting it.)

thanks, because in my code I acutally freeze(kill) the hitsory, that’s why . you have my day :slight_smile:

No problem.

Another obstacle to watch out for. When you are running your code, I’m noticing that the arc node won’t return a center until the UI is refreshed.

import maya.cmds as cmds
p1 = (0,1,1)
p2 = (0,2,3)
p3 = (0,4,5)
newNode = cmds.createNode('makeThreePointCircularArc')
cmds.setAttr(newNode + '.pt1', p1[0], p1[1], p1[2])
cmds.setAttr(newNode + '.pt2', p2[0], p2[1], p2[2])
cmds.setAttr(newNode + '.pt3', p3[0], p3[1], p3[2])
cmds.setAttr(newNode + '.d', 3)
cmds.setAttr(newNode + '.s', 4)
newCurve = cmds.createNode('nurbsCurve')
cmds.connectAttr(newNode + '.oc', newCurve + '.cr')
#cmds.delete(ch=1)
transformNode = cmds.listRelatives(newCurve, fullPath=True, parent=True)
cmds.rename(transformNode, 'arcCurve')


print(cmds.getAttr(newNode + '.center'))
# RESULT IS [(0,0,0)]

cmds.refresh()

print(cmds.getAttr(newNode + '.center'))
# RESULT IS [(0.0, 8.499999999999979, -1.499999999999985)]

yp, refresh UI is a bit annoying but will do the job for now. thank you so much

you could do it completely through vector math like this

def rayPlaneIntersection(rayOrigin: Vector, rayDirection: Vector, planeOrigin: Vector, planeNormal: Vector) -> Vector:

    distance = ((rayOrigin - planeOrigin) * planeNormal.normal())
    return rayOrigin - rayDirection * (distance / (rayDirection * planeNormal))

def centerOfCircle(point1: Vector, point2: Vector, point3: Vector) -> Vector:

    vec1 = point1 - point2
    vec2 = point3 - point2
    cross1 = vec1.normal() ^ vec2.normal()
    aim1 = vec1.normal() ^ cross1

    center1 = (vec1 * .5) + point2
    center2 = (vec2 * .5) + point2

    centerPoint = rayPlaneIntersection(center1, aim1, center2, vec2.normal())
    return centerPoint
2 Likes