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?

More than 1 year has passed since last update.

円に内接する四角形(等脚台形)「2022 慶応義塾大学 総合政策学部【5】」をsympyとFreeCADでやってみたい。

Last updated at Posted at 2023-08-19

・いつものベクトルの成分表示?です。
・問題文は2次元ですが、3次元FreeCADのマクロで、XY平面上に作図しました。

オリジナル(youtube)

上と同じです。大学入試数学問題集成 様>テキスト 【5】
???ジャンプの調子が悪いです。???

sympyで(MathLABO 様の方法で)

勉強中。

sympyで(ベクトルの成分表示?です。)

・仮ABCの外心を座標原点へ移動しました。
・全点の座標計算後、解答です。

from sympy import *
var('s,t',real=True)
def myTriangle_Move_CircumcenterToOrigin_Point(dumABC):
    dumO=dumABC.circumcircle.args[0]
    myT=Triangle( dumABC.vertices[0]-dumO,
                  dumABC.vertices[1]-dumO,
                  dumABC.vertices[2]-dumO )
    return myT.args[0],myT.args[1],myT.args[2]
def mySolve (a,b,c):
    ans=solve([ Eq(a.x,(s*b+t*c).x),
                Eq(a.y,(s*b+t*c).y) ],[s,t]  ) 
    return ans[s],ans[t] 
(AB     ,BC)     =(2,1)
(Rad_BAD,Rad_CDA)=(60*pi/180,60*pi/180)
dumA=     Point(0,0)
dumB=dumA+Point(AB*cos(Rad_BAD),AB*sin(Rad_BAD) )
dumC=dumB+Point(BC             ,0               )
(A,B,C)=myTriangle_Move_CircumcenterToOrigin_Point( Triangle( dumA,dumB,dumC ) )
(O)=( Point(0,0) )
(D)=( C+Point(AB*cos(Rad_CDA),AB*sin(-Rad_CDA))   )
print("#(1)",B.distance(D)        )
print("#(1)",Circle(A,B,C).radius )
print("#(2)",(B-A).dot(O-A)       )
print("#(2)",(D-A).dot(O-A)       )
print("#(3)",mySolve( O-A,B-A,D-A ))
#(1) sqrt(7)
#(1) sqrt(21)/3
#(2) 2
#(2) 9/2
#(3) (1/6, 4/9)

FreeCADのマクロで作図

・いつものベクトルの成分表示?です。
・問題文は2次元ですが、3次元FreeCADのマクロで、XY平面上に作図しました。

import FreeCAD
import Part
import DraftTools
import Draft
import Mesh
############################################################################
# 計算
from sympy import *
var('s,t',real=True)
def myTriangle_Move_CircumcenterToOrigin_Point(dumABC):
    dumO=dumABC.circumcircle.args[0]
    myT=Triangle( dumABC.vertices[0]-dumO,
                  dumABC.vertices[1]-dumO,
                  dumABC.vertices[2]-dumO )
    return myT.args[0],myT.args[1],myT.args[2]
def mySolve (a,b,c):
    ans=solve([ Eq(a.x,(s*b+t*c).x),
                Eq(a.y,(s*b+t*c).y) ],[s,t]  ) 
    return ans[s],ans[t] 
(AB     ,BC)     =(2,1)
(Rad_BAD,Rad_CDA)=(60*pi/180,60*pi/180)
dumA=     Point(0,0)
dumB=dumA+Point(AB*cos(Rad_BAD),AB*sin(Rad_BAD) )
dumC=dumB+Point(BC             ,0               )
(A,B,C)=myTriangle_Move_CircumcenterToOrigin_Point( Triangle( dumA,dumB,dumC ) )
(O)=( Point(0,0) )
(D)=( C+Point(AB*cos(Rad_CDA),AB*sin(-Rad_CDA))   )
print("#(1)",B.distance(D)        )
print("#(1)",Circle(A,B,C).radius )
print("#(2)",(B-A).dot(O-A)       )
print("#(2)",(D-A).dot(O-A)       )
print("#(3)",mySolve( O-A,B-A,D-A ))
#(1) sqrt(7)
#(1) sqrt(21)/3
#(2) 2
#(2) 9/2
#(3) (1/6, 4/9)
############################################################################
# 作図用
myCi=Circle( O,O.distance(A))
B2=A+mySolve( O-A,B-A,D-A )[0]*(B-A)
D2=A+mySolve( O-A,B-A,D-A )[1]*(D-A)
############################################################################
# 3D作図 z=0 XY平面に作図しました。
############################################################################
############################################################################
# 円の作図 FrecCADのdocより
# https://wiki.freecad.org/Macro_Circle
def Freecad3D_circle(x=0.0,y=0.0,z=0.0,radius=0.0,diameter=0.0,circumference=0.0,area=0.0,startangle=0.0,endangle=0.0,arc=0.0,anglecenter=0.0,cord=0.0,arrow=0.0,center=0,placemObject=""):
    from math import sqrt, pi
    if placemObject == "":
        pl = FreeCAD.Placement()
        pl.Rotation = FreeCADGui.ActiveDocument.ActiveView.getCameraOrientation()   
        pl.Base = FreeCAD.Vector(x,y,z)
    else:
        pl = FreeCAD.Placement()
        pl = placemObject                                  # placement imposted
    if diameter != 0:                                      # with diameter
        radius = diameter / 2.0
    elif circumference != 0:                               # with circumference
        radius = (circumference / pi) / 2.0
    elif area != 0:                                        # with area
        radius =  sqrt((area / pi))
    elif (cord != 0) and (arrow != 0):                     # with cord and arrow
        radius = ((arrow**2) + (cord**2) / 4.0) / (arrow*2) 
    elif (arc != 0) and (anglecenter != 0):                # with arc and anglecenter central in degrees
        radius = ((360/anglecenter)*arc) / pi/2.0
        if endangle != 0:
            startangle  = endangle - anglecenter
        endangle   = anglecenter + startangle
        startangle  = endangle - anglecenter
    if radius != 0:
        try:
            Draft.makeCircle(radius,placement=pl,face=False,startangle=startangle,endangle=endangle,support=None)
            if center != 0:
                x=pl.Base.x
                y=pl.Base.y
                z=pl.Base.z
                Draft.makePoint(x,y,z)
        except Exception:
            App.Console.PrintError("Unexpected keyword argument" + "\n")
        App.ActiveDocument.recompute()
    else:
        App.Console.PrintMessage("Unexpected keyword argument" + "\n")
        App.Console.PrintMessage("circle(x,y,z,radius,diameter,circumference,area,startangle,endangle,[arc,anglecenter],[cord,arrow],center,placemObject)" + "\n")
        App.Console.PrintMessage("circle(radius=10.0,placemObject=App.Placement(App.Vector(11,20,30), App.Rotation(30,40,0), App.Vector(0,0,0)))" + "\n")
    return
def myCircle_2D(myCi):
    x=myCi.center.x
    y=myCi.center.y
    r=myCi.radius
    Freecad3D_circle(
           x=float(x),y=float(y),z=0.0,
           radius=float(abs(r)),
           center=1,
           placemObject=App.Placement(App.Vector(float(x),float(y),0),
           App.Rotation(0,0,0),App.Vector(0,0,0)))
    return
############################################################################
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.15 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
#######################################################################################
myCircle_2D  ( myCi )
myLine_C_2D  ( A,B,C,D)
myLine_S_2D  ( B2,O)
myLine_S_2D  ( A ,O)
myLine_S_2D  ( D2,O)
myTxtXYZ_S_2D( O,"O",A,"A",B,"B",C,"C",D,"D" )
myTxtXYZ_S_2D( B2,"B2",D2,"D2" )
#######################################################################################
doc = App.activeDocument()
App.ActiveDocument.addObject("App::Origin", "Origin")
App.ActiveDocument.getObject('Origin').Visibility = True
![1png.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/7ca4cf9d-2045-712b-cad2-6d621e87ee9d.png)
![0png.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/a1b13033-87e8-b652-8228-fbf0d9859f21.png)
App.ActiveDocument.recompute()
Gui.activeDocument().activeView().viewAxonometric()
Gui.SendMsgToActiveView("ViewFit")

・isometric方向?です。
0png.png

・上空から?です。
・ちょっと気になる、点Aのy座標。マイナスでした。
・ベクトルAOをベクトルAB2とベクトルAD2に分解しました。

1png.png

sympyの実行環境

①私の環境は,pycharmです。
②よく聞くのは、Jupyterです。
③web上で、上記のソースを「SymPy Live shell」に、コピー貼り付けでもできました。
黒背景の右上に、マウスを移動すると、コピーマークが発生します。
??? タブレット環境で、コピー貼り付けが実行できませんでした。???

参考

以下、いつもの?おすすめです。

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?