LoginSignup
1
0

高校入試平面図形 相似「2024 千葉県高校入試 数学大問3(3)」をsympyとFreeCADでやってみたい。

Last updated at Posted at 2024-03-12

入試問題 sympy FreeCAD Python

問題文は2次元ですが、3次元FreeCADのマクロで、XY平面上に作図しました。
私の解答の方法は、中学生の学習指導要領の範囲外です。 ベクトル成分表示です。
後半は、正弦定理を使っています。

オリジナル

数学を数楽に 様 
youtube (10:11) 大問3(3)

東進 様
https://www.toshin.com/koukou_nyushi/files/2024/sugaku_q/chiba_sugaku_q.pdf#page=9
<2024年全国公立高校入試解答速報|大学受験の予備校・塾 東進
https://www.toshin.com/koukou_nyushi/

sympyで(オリジナル 様のやり方で) できました。

・ver0.1
>直角三角形の相似がたくさんある。
>相似はかくれんぼ。
>2つ45°
>探せばいい

# ver0.1
from sympy import *
var('x,EBF',real=True,nonnegative=True)
x  =solve(Eq((15+x)/6,9/x),x)[0]             #;print("# x  =",x)
CF =sqrt (x**2+6**2)                         #;print("# CF =",CF)
EBF=solve(Eq(CF**2/15**2,6*x/2/EBF),EBF)[0]   ;print("# EBF=",EBF)
# EBF= 45

sympyで(いつものやり方で)

・ver0.2
・arctanでできませんでした。

# ver0.2
# from sympy import *
# var('x',real=True,nonnegative=True)
# y=(atan(9/x)+atan(6/x))*180/pi
# sol=solveset( Eq(y,45.0),x,Interval(17,19)   )    ;print("#",sol)
# # 
# # from sympy.plotting import plot
# # plot(0,45,y,(x,0,30))
# # ConditionSet(x, Eq(180*atan(6/x) + 180*atan(9/x) - 45.0*pi, 0), Interval(17, 19))

・ver0.3
・できました。正弦定理で。
・ベクトルの成分表示です。
・プログラム後半は、作図用です。三角形を回転しています。
Return the non-reflex angle formed by rays emanating from the origin with directions the same as the direction vectors of the linear entities.
https://docs.sympy.org/latest/modules/geometry/lines.html#sympy.geometry.line.LinearEntity.angle_between
Rotate angle radians counterclockwise about Point pt.
https://docs.sympy.org/latest/modules/geometry/points.html#sympy.geometry.point.Point2D.rotate

# ver0.3
from sympy import *
var('R',real=True,nonnegative=True)
deg,AD,DC=45,9,6
R =solve( Eq( (AD+DC)/sin(deg/180*pi),2*R),R)[0]
ax=Rational(1,2)*(AD+DC)
dx= ax-AD
O =Point(  0 ,0)
A =Point( ax ,-sqrt(R**2-ax**2))            
C =Point(-A.x,A.y)                          
D =Point( dx ,A.y)
B =Point( D.x,sqrt(R**2-(DC-ax)**2))         
E =Line(A,B).projection(C)
F =Line(B,D).intersection(Line(C,E))[0]
print("# EBF=",Triangle(E,B,F).area)
# EBF= 45
#
myRot=3/2*pi-Line(O,(C+B)/2).angle_between(Line(O,Point(1,0)))
A =A.rotate(myRot)                          
B =B.rotate(myRot)                          
C =C.rotate(myRot)                          
D =D.rotate(myRot)                          
E =E.rotate(myRot)                          
F =F.rotate(myRot)                          
# EBF= 45

・ver0.4
・極座標でできませんでした。

# ver0.4
# from sympy import *
# var('R,θA,θC',real=True,nonnegative=True)
# deg,AD,DC=45,9,6
# R=solve( Eq( (AD+DC)/sin(deg/180*pi),2*R),R)[0]
# A=Point( R*cos(θA), R*sin(θA))         
# B=Point(-R*cos(θC),-R*sin(θC))         
# C=Point( R*cos(θC),-R*sin(θC))         
# D=Line(A,C).projection(B)                                           #;print("# D  =",D)
# sol=solve( [Eq(A.distance(D),AD),Eq(D.distance(C),DC)] ,[θA,θC])   ;print("# sol=",sol)

FreeCADのマクロで作図

・計算部分は、コピー貼り付けです。

import FreeCAD
import Part
import DraftTools
import Draft
import Mesh
############################################################################
# 計算
# ver0.3
from sympy import *
var('R',real=True,nonnegative=True)
deg,AD,DC=45,9,6
R =solve( Eq( (AD+DC)/sin(deg/180*pi),2*R),R)[0]
ax=Rational(1,2)*(AD+DC)
dx= ax-AD
O =Point(  0 ,0)
A =Point( ax ,-sqrt(R**2-ax**2))            
C =Point(-A.x,A.y)                          
D =Point( dx ,A.y)
B =Point( D.x,sqrt(R**2-(DC-ax)**2))         
E =Line(A,B).projection(C)
F =Line(B,D).intersection(Line(C,E))[0]
print("# EBF=",Triangle(E,B,F).area)
#
myRot=3/2*pi-Line(O,(C+B)/2).angle_between(Line(O,Point(1,0)))
print("# myRot=",myRot*180/pi,float(myRot*180/pi) )
A =A.rotate(myRot)                          
B =B.rotate(myRot)                          
C =C.rotate(myRot)                          
D =D.rotate(myRot)                          
E =E.rotate(myRot)                          
F =F.rotate(myRot)                          
print("# B=",B )
print("# C=",C )
############################################################################
# 作図用
############################################################################
# 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.8 mm'
    FreeCADGui.ActiveDocument.ActiveObject.FontSize = '1.5 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)
myLine_S_2D     (B,D)
myLine_S_2D     (C,E)
myTxtXYZ_S_2D(O,"O",A,"A",B,"B",C,"C",D,"D",E,"E",F,"F")
myCircle_2D      (Circle(Point(0, 0), R)) 
#######################################################################################
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")

・問題文は2次元ですが、3次元FreeCADのマクロで、XY平面上に作図しました。
・isometric方向です。
1.png
・上空からです。拡大図
2.png

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

(テンプレート)

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

「この記事は以下の記事からリンクされています」で。

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