0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

材料力学「平行弦ワンレントラス 三角形2個」sympyのTrussのソースコードからクレモナ図(Cremona diagram) をAI先生に聞きました。

Last updated at Posted at 2025-06-01

・私がわかりませんでした。
・タイトル。変更予定です。

開始

以下のソースコードのトラスのクレモナ図を教えて下さい。
# 平行弦ワンレントラス
from sympy.physics.continuum_mechanics.truss import Truss
import math
from sympy import *
var('S1 S2 S3 S4 S5')
P=1   # var('P')
L=1   # var('L')
t = Truss()
t.add_node     ((2,Rational(1,2)*L,Rational(1,2)*L*sqrt(3)), \
                (4,Rational(3,2)*L,Rational(1,2)*L*sqrt(3)))                       
t.add_node     ((1,0,0) ,(3,L,0)) 
t.add_member   ((S1,1,2),(S2,1,3),(S3,2,3))   
t.add_member   ((S4,2,4),(S5,3,4))   
t.apply_support((1,"pinned"), (3,"roller"))
t.apply_load   ((4,P,270))
p = t.draw()
p.show()
# 
t.solve()
print("#",t.internal_forces)
print("#",t.reaction_loads )           
# {S1: sqrt(3)/3, S2: -sqrt(3)/6, S3: -sqrt(3)/3, S4: sqrt(3)/3, S5: -2*sqrt(3)/3}
# {'R_1_x': 0, 'R_1_y': -1/2, 'R_3_y': 3/2}

(本日の)ChatGPT先生へ

質問リスト

・質問リストの追番は無視して下さい。1個ずつです。途中の回答表示は省略しています。
・以下のソースコードは、上記のことです。

# 質問リスト
1. 以下のソースコードのトラスのクレモナ図を教えて下さい。  
2. 希望します。  
3. 間違っていませんか。  
4. 私の質問をMarkdown形式でリスト化して出力して。Markdown形式でリストからアスタリスクは削除して。1行目に、# 質問リスト の文字を出力して。最後の質問も追加して下さい。追番を追加して下さい。Markdown形式で。  
5. 私の質問をMarkdown形式でリスト化して出力して。Markdown形式でリストからアスタリスクは削除して。1行目に、# 質問リスト の文字を出力して。最後の質問も追加して下さい。追番を追加して下さい。Markdown形式で。  

・(再)私がわかりませんでした。
✅ 修正済スクリプト(FreeCAD)

import FreeCAD as App
import Draft
import math

doc = App.ActiveDocument if App.ActiveDocument else App.newDocument()

# スケール調整
scale = 5 / (math.sqrt(3)/6)

# 力の大きさ
F = {
    "S1":  math.sqrt(3)/3,
    "S2": -math.sqrt(3)/6,
    "S3": -math.sqrt(3)/3,
    "S4":  math.sqrt(3)/3,
    "S5": -2*math.sqrt(3)/3,
    "R1":  0.5,
    "R3":  1.5,
    "P":   -1,
}

# 単位ベクトル(方向)
V = {
    "R1": App.Vector(0, 1),
    "S1": App.Vector(1/2, math.sqrt(3)/2).normalize(),
    "S2": App.Vector(1, 0),
    "S3": App.Vector(1/2, -math.sqrt(3)/2).normalize(),
    "S4": App.Vector(1, 0),
    "S5": App.Vector(-1/2, math.sqrt(3)/2).normalize(),
    "R3": App.Vector(0, 1),
    "P":  App.Vector(0, -1),
}

# ベクトル描画
def add_vector(start, name, length, direction):
    vec = direction.multiply(length * scale)
    end = start.add(vec)
    Draft.makeWire([start, end])
    Draft.makeText([name], point=start.add(vec.multiply(0.5)))
    return end

# 節点1: R1 → S1 → S2 → 戻る(ABC)
A = App.Vector(0, 0)
B = add_vector(A, "R1", F["R1"], V["R1"])
C = add_vector(B, "S1", F["S1"], V["S1"])
A2 = add_vector(C, "S2", F["S2"], V["S2"])  # 戻る

# 節点2: S1 → S4 → S3(CBD)
C2 = C
B2 = B
D = add_vector(B2, "S4", F["S4"], V["S4"])
C3 = add_vector(D, "S3", F["S3"], V["S3"])

# 節点3: S2 → S3 → S5 → R3(ACDE)
A3 = A
C4 = C2
D2 = D
E = add_vector(D2, "S5", F["S5"], V["S5"])
A4 = add_vector(E, "R3", F["R3"], V["R3"])

# 節点4: S4 → S5 → 荷重(DBE)
B3 = B2
D3 = D2
E2 = E
F_ = add_vector(D3, "P", F["P"], V["P"])

App.ActiveDocument.recompute()

・???

111.png

(本日の)Gemini先生へ

・私の実際の質問リスト

質問リスト
1.以下のソースコードのトラスのクレモナ図を教えて下さい。
  ...
2.Freecadのマクロを教えて下さい。
3.私の質問をMarkdown形式でリスト化して出力して。Markdown形式でリストからアスタリスクは削除して。1行目に、# 質問リスト の文字を出力して。最後の質問も追加して下さい。追番を追加して下さい。Markdown形式で。

・先生の質問リストの回答

質問リスト
1.トラスのクレモナ図について
2.FreeCADのマクロについて
3.FreeCADのマクロを使って、クレモナ図を自動生成する方法について

・: name 'math' is not defined
 上記の対応がわからなかったので、あきらめました。

import FreeCAD
import Part
import Draft

# 例として、SymPyから得られた内力データ
# これは手動でFreeCADマクロにコピー&ペーストするか、ファイルから読み込む必要があります
internal_forces = {
    'S1': math.sqrt(3)/3,
    'S2': -math.sqrt(3)/6,
    'S3': -math.sqrt(3)/3,
    'S4': math.sqrt(3)/3,
    'S5': -2*math.sqrt(3)/3
}

reaction_loads = {
    'R_1_x': 0,
    'R_1_y': -0.5,
    'R_3_y': 1.5
}

# FreeCADドキュメントの取得
doc = FreeCAD.activeDocument()
if doc is None:
    doc = FreeCAD.newDocument("CremonaDiagram")

# クレモナ図の描画原点
current_point = FreeCAD.Vector(0, 0, 0)

# 例として、反力R_1_yを描画
# R_1_y は下向きなので、y座標を減らす
force_scale = 100 # クレモナ図の力の大きさを拡大するスケール
p_start = current_point
p_end = FreeCAD.Vector(current_point.x + reaction_loads['R_1_x'] * force_scale,
                       current_point.y + reaction_loads['R_1_y'] * force_scale,
                       current_point.z)
doc.addObject("Part::Line", "R1y_line").Shape = Part.LineSegment(p_start, p_end).toShape()
Draft.make_text("R1y", p_end + FreeCAD.Vector(0.1, 0.1, 0))
current_point = p_end

# S1の力を描画 (方向はトラス図から判断してベクトルを調整する必要がある)
# S1が引張の場合、節点から離れる方向に力を描く
# これは簡略化された例であり、実際のクレモナ図の作図ロジックはより複雑です
# 例えば、節点1に作用するS1の力は、その部材の角度と内力S1の大きさによって決定されます
# この例では、単純に現在の点から適当な方向に力を描いています
s1_magnitude = internal_forces['S1']
# S1の方向をFreeCAD上で表現するためのベクトル (要手動調整または計算)
s1_direction_vector = FreeCAD.Vector(1, 0.5, 0).normalize() # 仮の方向
if s1_magnitude > 0: # 引張
    p_start_s1 = current_point
    p_end_s1 = current_point + s1_direction_vector * s1_magnitude * force_scale
else: # 圧縮
    p_start_s1 = current_point
    p_end_s1 = current_point + s1_direction_vector * s1_magnitude * force_scale # 負の力なので反対方向

doc.addObject("Part::Line", "S1_line").Shape = Part.LineSegment(p_start_s1, p_end_s1).toShape()
Draft.make_text("S1", p_end_s1 + FreeCAD.Vector(0.1, 0.1, 0))
current_point = p_end_s1


doc.recompute()
Gui.SendMsgToStatusBar("Cremona Diagram Macro executed.")

copilot先生へ

いつもの? sympyの実行環境と 参考のおすすめです。

(テンプレート)

いつもと違うおすすめです。

Qiita内

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?