LoginSignup
0
0

平面図形「2021 青森公立大学前期 経営経済学部【4】」をsympyとFreeCADでやってみたい。

Last updated at Posted at 2023-08-10

・問題文は2次元ですが、3次元FreeCADのマクロで、XY平面上に作図しました。
 いつものベクトルの成分表示?です。
・問題文に「このとき,AE=10/9となる.」は、いらないようです?助かります。
 どなたか、解説をお願いします。

オリジナル
T氏の数学日記 様

数学入試問題 様

上と同じです。大学入試数学問題集成>テキスト【4】

公式ホームページ 2019年度〜2023年度入学者選抜

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

勉強中。チェバの定理,メネラウスの定理。いつものゆうどうです。

sympyで(sympyのベクトルの座標表示です。)

・チェバの定理,メネラウスの定理を使っていません。
・最初のTriangleを外心座標を使って、Triangleを原点へ移動しています。

from sympy import *
(AB,BC,CA)=(6,4,5)
dumABC=Triangle(sss=(AB,BC,CA))
dumO  =dumABC.circumcircle.args[0]
ABC=Triangle( dumABC.vertices[0]-dumO,
              dumABC.vertices[1]-dumO,
              dumABC.vertices[2]-dumO )
O      =Point(0,0)
(A,B,C)=(ABC.vertices[0],ABC.vertices[1],ABC.vertices[2])
D=ABC.circumcircle.intersection( Line(B,O))[0]
E=Line(A,B).intersection(Line(C,D))[0]
F=Line(A,C).intersection(Line(B,D))[0]
G=Line(B,C).intersection(Line(E,F))[0]
print("#問題1 R ",ABC.circumcircle.args[1])
print("#問題2 DE",D.distance(E))
print("#問題2 AE",A.distance(E))
print("#問題3   ",E.distance(F)/F.distance(G))
#問題1 R  8*sqrt(7)/7
#問題2 DE 32*sqrt(7)/63
#問題2 AE 10/9
#問題3    13/27

sympyで(最後にsubsは、私は、ずうずうしいみたいです。できませんでした。)

全部変数表示の意味です。

from sympy import *
AB,BC,CA=symbols('AB,BC,CA',real=True)
dumABC=Triangle(sss=(AB,BC,CA))
print("#",dumABC)
# ...
# (AB,BC,CA)=(6,4,5)
# 
# None

FreeCADのマクロで作図

問題文は2次元ですが、3次元FreeCADのマクロで、XY平面上に作図しました。

import FreeCAD
import Part
import DraftTools
import Draft
import Mesh
############################################################################
# 計算
# aomori kouritu 2021 [4]-1
from sympy import *
(AB,BC,CA)=(6,4,5)
dumABC=Triangle(sss=(AB,BC,CA))
dumO  =dumABC.circumcircle.args[0]
ABC=Triangle( dumABC.vertices[0]-dumO,
              dumABC.vertices[1]-dumO,
              dumABC.vertices[2]-dumO )
O      =Point(0,0)
(A,B,C)=(ABC.vertices[0],ABC.vertices[1],ABC.vertices[2])
D=ABC.circumcircle.intersection( Line(B,O))[0]
E=Line(A,B).intersection(Line(C,D))[0]
F=Line(A,C).intersection(Line(B,D))[0]
G=Line(B,C).intersection(Line(E,F))[0]
print("#問題1 R ",ABC.circumcircle.args[1])
print("#問題2 DE",D.distance(E))
print("#問題2 AE",A.distance(E))
print("#問題3   ",E.distance(F)/F.distance(G))
############################################################################
# 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.3 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_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( ABC.circumcircle )
myLine_C_2D  ( A,B,C )
myLine_2D    ( A,E )
myLine_2D    ( B,D )
myLine_2D    ( C,E )
myLine_2D    ( E,G )
myTxtXYZ_S_2D( O,"O",A,"A",B,"B",C,"C" )
myTxtXYZ_S_2D( D,"D",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方向?です。
0png.png

上空から?です。
マウス操作で、Originは、非表示。
マウス操作で、文字の緑色は。勉強中。
マウス操作で、文字の移動。勉強中。
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