ボディが立方体か?を判断したいんです。
で、こんな感じで作りました。
#Fusion360API Python script #Author-kantoku #Description-立方体の判断 import adsk.core, adsk.fusion, traceback def run(context): ui = None try: app :adsk.core.Application = adsk.core.Application.get() ui :adsk.core.UserInterface = app.userInterface des :adsk.fusion.Design = app.activeProduct root :adsk.fusion.Component = des.rootComponent res = [] for body in root.bRepBodies: res.append('[{}]-{}'.format(body.name, isCube(body))) msg = 'ルートコンポーネント内のボディが立方体かどうか?\n' + '\n'.join(res) ui.messageBox(msg) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) def isCube( body :adsk.fusion.BRepBody) -> bool: # エッジの長さは同じか? if len(set([round(eg.length, 4) for eg in body.edges])) > 1: return False # 各面積は同じか? if len(set([round(fc.area, 4) for fc in body.faces])) > 1: return False # すべて平面か? flat = adsk.core.SurfaceTypes.PlaneSurfaceType if len([fc for fc in body.faces if fc.geometry.surfaceType != flat]) > 0: return False return True
isCube関数がそうなんですが、パッと思いついた範囲で
1)全てのエッジの長さが等しい
2)全ての面積が等しい
3)全ての面が平面
に、してみました。
本当はオイラーの多面体定理でチェックしたり、隣り合う面やエッジが直交しているか
チェックしたりすべきなのかもしれませんが、手っ取り早く行いたいんです。
ただよく考えると、「1」の条件が必要なのかな・・・。
立方体以外で「2」「3」を満たす形状が思いつかないんだよなぁ。
底面が菱形の場合・・・も満たす形状は無いはず。どうしよう。