正五角形「2023京都大学前期文系【３】」をWolframAlphaとsympyとFreeCADでやってみたい。

問題文は2次元ですが、作図は、３次元FreeCADのマクロです。
sympyのplotモジュールでも作図できました。

オリジナル

https://youtu.be/3BPA_kuaTSE

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

https://mathexamtest.web.fc2.com/2023/202310541/2023105410100mj.html#top-0110

# WolframAlphaで【３】(1)の計算だけ 別の形

https://www.wolframalpha.com/input?i=TrigExpand%5Bcos2%CE%98%5D&lang=ja

別の形
2 cos^2(Θ) - 1

https://www.wolframalpha.com/input?i=TrigExpand%5Bcos3%CE%98%5D&lang=ja

別の形
4 cos^3(Θ) - 3 cos(Θ)

# WolframAlphaで【３】(1)の計算だけ

https://www.wolframalpha.com/input?i=cos2%CE%B8&lang=ja

多引数の公式
cos(2 θ) = -1 + 2 cos^2(θ)

https://www.wolframalpha.com/input?i=cos3%CE%B8&lang=ja

多引数の公式
cos(3 θ) = cos(θ) (-1 + 2 cos(2 θ))

# sympyで計算だけ
(1)を使う方法を勉強中

```python
from sympy import *
theta=Symbol('theta',real=True)
t    =Symbol('t'    ,real=True)
print("#(1)",expand_trig(cos(2*theta)))
print("#(1)",expand_trig(cos(3*theta)))
t=(2*pi)/5
A=Point(cos(pi/2-t*0),sin(pi/2-t*0))
B=Point(cos(pi/2-t*1),sin(pi/2-t*1))
print("#(2)",A.distance(B),float(A.distance(B)))
#(1) 2*cos(theta)**2 - 1
#(1) 4*cos(theta)**3 - 3*cos(theta)
#(2) sqrt(sqrt(5)/8 + (5/4 - sqrt(5)/4)**2 + 5/8) 1.1755705045849463
```

# sympyとFreeCADのマクロで(計算と作図)

```python
import FreeCAD
import Part
import Draft
import Mesh
#########################################################################################################
# 計算
from sympy import *
import matplotlib.pyplot as plt
theta=Symbol('theta',real=True)
print("#(1)",expand_trig(cos(2*theta)))
print("#(1)",expand_trig(cos(3*theta)))
#
x=Symbol('x',real=True)
y=Symbol('y',real=True)
t=Symbol('t',real=True)
t=(2*pi)/5
A=Point(cos(pi/2-t*0),sin(pi/2-t*0))
B=Point(cos(pi/2-t*1),sin(pi/2-t*1))
C=Point(cos(pi/2-t*2),sin(pi/2-t*2))
D=Point(cos(pi/2-t*3),sin(pi/2-t*3))
E=Point(cos(pi/2-t*4),sin(pi/2-t*4))
print("#(2)",A.distance(B),float(A.distance(B)))
#
p=       plot(solve(Line(A,B).equation(),y)[0],(x,A.x,B.x),line_color="red",show=False)
p.extend(plot(solve(Line(B,C).equation(),y)[0],(x,B.x,C.x),line_color="red",show=False))
p.extend(plot(solve(Line(C,D).equation(),y)[0],(x,C.x,D.x),line_color="red",show=False))
p.extend(plot(solve(Line(D,E).equation(),y)[0],(x,D.x,E.x),line_color="red",show=False))
p.extend(plot(solve(Line(E,A).equation(),y)[0],(x,E.x,A.x),line_color="red",show=False))
#
expr = sqrt(1-x**2)
p.extend(plot( expr, line_color="blue", show=False))
p.extend(plot(-expr, line_color="blue", show=False))
plt.rcParams['figure.figsize']=5,5
p.show()
##########################################################################################################
### 3D作図
# 円の作図　FrecCADのdocより
# https://wiki.freecad.org/Macro_Circle
def 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(x,y,r):
    circle(x=float(x),y=float(y),z=0.0,
           radius=float(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) +  ')'
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.2 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
doc = App.activeDocument()
myTxtXYZ_S_2D(A,"A",B,"B")
myLine_C_2D  (A,B,C,D,E)
myCircle_2D  (0,0,1)
#
App.ActiveDocument.addObject("App::Origin", "Origin")
App.ActiveDocument.getObject('Origin').Visibility = True
App.ActiveDocument.recompute()
Gui.activeDocument().activeView().viewAxonometric()
Gui.SendMsgToActiveView("ViewFit")
#(1) 2*cos(theta)**2 - 1
#(1) 4*cos(theta)**3 - 3*cos(theta)
#(2) sqrt(sqrt(5)/8 + (5/4 - sqrt(5)/4)**2 + 5/8) 1.1755705045849463
```

plotで作図。

![1png.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/316bbfc9-1aac-354e-4c4c-3ac61630bb2f.png)

FreeCADで作図。

![2png.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/7ec36dbb-669b-cd1c-e350-0c50d761cf8d.png)

真上から見た。

![3png.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/7ffbd2cf-b60c-e43e-95c3-f2167be4c4af.png)

# 参考

https://qiita.com/mrrclb48z/items/b7742bd57151dc35fdf6

https://reference.wolfram.com/language/ref/TrigExpand.html.ja?source=footer

https://docs.sympy.org/latest/tutorials/intro-tutorial/simplification.html#trigonometric-simplification