こちらの続きです。
穴テンプレートのトーラスを考える2 - C#ATIA
誤った結果となる原因の一つの
"円弧の始点終点では無く、穴の軸方向を元に三次元座標の上下で判断"
を組み込みつつ、出力結果を下6桁に修正しました。
# Fusion360API Python script import traceback import adsk.core as core import adsk.fusion as fusion def run(context): ui: core.UserInterface = None try: app: core.Application = core.Application.get() ui = app.userInterface msg: str = 'Select' selFilter: str = 'ToroidalFaces' sel: core.Selection = select_ent(msg, selFilter) if not sel: return face: fusion.BRepFace = sel.entity eva: core.SurfaceEvaluator = face.evaluator prmBox: core.BoundingBox2D = eva.parametricRange() midPrm: core.Point2D = core.Point2D.create( (prmBox.minPoint.x + prmBox.maxPoint.x) * 0.5, (prmBox.minPoint.y + prmBox.maxPoint.y) * 0.5, ) for isU in (True, False): arc: core.Arc3D = core.Arc3D.cast( eva.getIsoCurve(midPrm.x, isU)[0] ) if arc: break if not arc: return torus: core.Torus = face.geometry _, origin, axis, _, _ = torus.getData() pnt: core.Point3D = origin.copy() normal: core.Vector3D = axis.copy() normal.scaleBy(100) pnt.translateBy(normal) plane: core.Plane = core.Plane.create(pnt, normal) pointDistanceData = [] measMgr: core.MeasureManager = app.measureManager for p in (arc.startPoint, arc.endPoint): res: core.MeasureResults = measMgr.measureMinimumDistance(plane, p) pointDistanceData.append( { "dist": res.value, "point": p, } ) pointDistanceData.sort(key = lambda x: x["dist"]) vec: core.Vector3D = arc.center.vectorTo(origin) bottomVec: core.Vector3D = arc.center.vectorTo(pointDistanceData[0]["point"]) topVec: core.Vector3D = arc.center.vectorTo(pointDistanceData[1]["point"]) msg = [ f"bottomAngle:{round(vec.angleTo(bottomVec),6)} ", f"topAngle:{round(vec.angleTo(topVec),6)} ", ] app.log(" / ".join(msg)) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) def select_ent( msg: str, filter: str ) -> core.Selection: try: app: core.Application = core.Application.get() ui: core.UserInterface = app.userInterface sel = ui.selectEntity(msg, filter) return sel except: return None
十分汚い。
結果は凸はこんな感じ。
bottomAngle:0.0 / topAngle:1.570796
凹はこんな感じ。
bottomAngle:1.570796 / topAngle:3.141593
凹のbottomAngleが正しくないです。原因は2個のベクトル間の
角度をVector3D.angleToメソッドで測定すると、近い方の角度を
返してくる事でしょう。