LoginSignup
1
0

算数:中学入試レベル平面図形「意外と難しい角度問題(youtube)」をsympyとFreeCADでやってみたい。

Last updated at Posted at 2024-05-25

・問題文は2次元ですが、3次元FreeCADのマクロで、XY平面上に作図しました。
・今回私は、FreeCADの操作で寸法線が書けるようになりました。(自慢しています。)

オリジナル

(0:00〜5:26)

sympyで(オリジナル 様の方法で)

・??? 勉強中

sympyで

>sympy docより
https://docs.sympy.org/latest/modules/geometry/lines.html#sympy.geometry.line.LinearEntity.angle_between

from sympy import *
s=1
A,B,C,D=map(Point,[(0,s*2),(0,0),(s*2,0),(s*2,s*2)])
E,F,G  =map(Point,[(s,s*2),(0,s),(s*3,0)]          )
# H 
I      =Line(C,E).intersection(Line(F,G))[0]
# J
print("#",Line(I,E).angle_between(Line(I,F))*180/pi)
# 45

FreeCADのマクロで作図

・3次元FreeCADのワイヤーフレームです。
・マクロプログラムの計算部分は、コピーしています。

import FreeCAD
import Part
import DraftTools
import Draft
import Mesh
############################################################################
# 計算
from sympy import *
s=1
A,B,C,D=map(Point,[(0,s*2),(0,0),(s*2,0),(s*2,s*2)])
E,F,G  =map(Point,[(s,s*2),(0,s),(s*3,0)]          )
# H 
I      =Line(C,E).intersection(Line(F,G))[0]
# J
print("#",Line(I,E).angle_between(Line(I,F))*180/pi)
# 45
############################################################################
# 作図用
############################################################################
# 3D作図 z=0 XY平面に作図しました。
############################################################################
def myXYZ2Txt_2D(A):
    return '(' + str(A.x) + ',' + str(A.y) +  ')'
    # return ""
def myTxtXYZ_2D(A,myWedgei):
    P5x=float(A.x)
    P5y=float(A.y)
    P5z=0.0
    p5 = FreeCAD.Vector(P5x, P5y, P5z)
    myText = Draft.makeText(myWedgei, p5)
    myText.Label = myWedgei
    FreeCADGui.ActiveDocument.ActiveObject.FontSize = '0.1 mm'
    return
def myTxtXYZ_S_2D(*xy_tx):
    for i in range(1,int(len(xy_tx)/2)+1):
        myTxtXYZ_2D(xy_tx[2*i-2],xy_tx[2*i-1]+myXYZ2Txt_2D(xy_tx[2*i-2]) )
    return
def myLine_2D(A,B):
    Ax,Ay,Az=float(A.x),float(A.y),0.0
    Bx,By,Bz=float(B.x),float(B.y),0.0
    pl = FreeCAD.Placement()
    pl.Rotation.Q = (0.4247081540122249, 0.17592004639554645, 0.33985110062924484, 0.8204732460821097)
    pl.Base = FreeCAD.Vector(-3.9166066876399563, -2.1670824762243774, 1.7495260956243028)
    points = [FreeCAD.Vector(Ax,Ay,Az), FreeCAD.Vector(Bx,By,Bz)]
    line = Draft.make_wire(points, placement=pl, closed=False, face=True, support=None)
    Draft.autogroup(line)
    return
def myLine_S_2D(*args):
    for i in range(1,len(args)):
        myLine_2D(args[i-1],args[i])
    return
def myLine_C_2D(*args):
    for i in range(1,len(args)):
        myLine_2D(args[i-1],args[i])
    myLine_2D(args[i],args[0])
    return
#######################################################################################
myLine_C_2D  (A,B,C,D)
myLine_S_2D  (B,E,C,G,F)
myTxtXYZ_S_2D(A,"A",B,"B",C,"C",D,"D" )
myTxtXYZ_S_2D(I,"I",E,"E",F,"F",G,"G" )
#######################################################################################
doc = App.activeDocument()
App.ActiveDocument.addObject("App::Origin", "Origin")
# App.ActiveDocument.getObject('Origin').Visibility = True
App.ActiveDocument.recompute()
Gui.activeDocument().activeView().viewAxonometric()
Gui.SendMsgToActiveView("ViewFit")

isometric方向?です。

1.png

拡大図

2.png

拡大図(CADの操作で寸法線を追加)
・(青色の)角度寸法は、ニセモノです。Part>計測>角度計算 です。
・角度寸法の表示は、勉強中です。

3.png

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

(テンプレート)

1
0
1

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
1
0