空間図形「2010（H22)年度京都大学前期文系【５】,理系【６】」をsympyとFreeCADでやってみたい。

The Spinning Cube立方体の回転
**オイラー角について、おすすめの本、サイトを教えて下さい。**

オリジナル
中央部は,r^2が,tに関する2次式となります。＜

http://k-kyogoku2.com/cn102/cn10/pg55.html

上と同じです。大学入試数学問題集成＞文系【５】,理系【６】

https://mathexamtest.web.fc2.com/2010/201010541/2010105410100mj.html#top-0106


# 参考

https://qiita.com/mrrclb48z/items/70bc83911d220b1eddaf


# sympyで
```python
from sympy import *
var('t')
def sxy(O,F,A):
    return Line(O,F).projection(A).distance(O), \
           Line(O,F).projection(A).distance(A)
O=Point3D(0, 0, 0)
A=Point3D(1, 0, 0)
B=Point3D(1, 1, 0)
C=Point3D(0, 1, 0)
D=Point3D(0, 0, 1)
E=Point3D(1, 0, 1)
F=Point3D(1, 1, 1)
G=Point3D(0, 1, 1)
print("#(1) ",Line(O,F).projection(A).distance(A))
print("#(2)O",sxy(O,F,O))
print("#(2)A",sxy(O,F,A))
print("#(2)B",sxy(O,F,B))
print("#(2)C",sxy(O,F,C))
print("#(2)D",sxy(O,F,D))
print("#(2)E",sxy(O,F,E))
print("#(2)F",sxy(O,F,F))
print("#(2)G",sxy(O,F,G))
# (O),(ACD),(BEG),(F)
P=t*F/F.distance(O)
y1=Plane(P,normal_vector=(1,1,1)).intersection(Line(O,A))[0].distance(P)
y2=Plane(P,normal_vector=(1,1,1)).intersection(Line(A,E))[0].distance(P)
y3=Plane(P,normal_vector=(1,1,1)).intersection(Line(E,F))[0].distance(P)
print("#(2) " , \
   pi*integrate(y1**2,(t,0          ,1*sqrt(3)/3)) \
  +pi*integrate(y2**2,(t,1*sqrt(3)/3,2*sqrt(3)/3)) \
  +pi*integrate(y3**2,(t,2*sqrt(3)/3,3*sqrt(3)/3)) )
#(1)  sqrt(6)/3
#(2)O (0, 0)
#(2)A (sqrt(3)/3, sqrt(6)/3)
#(2)B (2*sqrt(3)/3, sqrt(6)/3)
#(2)C (sqrt(3)/3, sqrt(6)/3)
#(2)D (sqrt(3)/3, sqrt(6)/3)
#(2)E (2*sqrt(3)/3, sqrt(6)/3)
#(2)F (sqrt(3), 0)
#(2)G (2*sqrt(3)/3, sqrt(6)/3)
#(2)  sqrt(3)*pi/3
```

# 苦しまぎれの?FreeCADのマクロで
空間図形の座標変換の勉強不足でした。
オイラー角を使ってみたい。
YZ平面で、切断したいです。アドバイスをお願いします。

![png1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/0a530922-830e-6f4e-fcc8-79dd7b1c43b7.png)

an Isometric view

![png2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/bde36e93-7ae2-8784-5cef-419cf54376a9.png)


マクロを途中で止めました。回転前です。

![png4.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/dde3e177-edac-0919-d149-1159ade5d7ae.png)

an Isometric view

![png3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/39a4a250-077a-0b93-d68e-90d3e8e94a7a.png)



```python
import FreeCAD
import Part
import Draft
import Mesh
#########################################################################################################
from sympy import *
var('t')
def sxy(O,F,A):
    return Line(O,F).projection(A).distance(O), \
           Line(O,F).projection(A).distance(A)
O=Point3D(0, 0, 0)
A=Point3D(1, 0, 0)
B=Point3D(1, 1, 0)
C=Point3D(0, 1, 0)
D=Point3D(0, 0, 1)
E=Point3D(1, 0, 1)
F=Point3D(1, 1, 1)
G=Point3D(0, 1, 1)
print("#(1) ",Line(O,F).projection(A).distance(A))
print("#(2)O",sxy(O,F,O))
print("#(2)A",sxy(O,F,A))
print("#(2)B",sxy(O,F,B))
print("#(2)C",sxy(O,F,C))
print("#(2)D",sxy(O,F,D))
print("#(2)E",sxy(O,F,E))
print("#(2)F",sxy(O,F,F))
print("#(2)G",sxy(O,F,G))
# (O),(ACD),(BEG),(F)
P=t*F/F.distance(O)
y1=Plane(P,normal_vector=(1,1,1)).intersection(Line(O,A))[0].distance(P)
y2=Plane(P,normal_vector=(1,1,1)).intersection(Line(A,E))[0].distance(P)
y3=Plane(P,normal_vector=(1,1,1)).intersection(Line(E,F))[0].distance(P)
print("#(2) " , \
   pi*integrate(y1**2,(t,0          ,1*sqrt(3)/3)) \
  +pi*integrate(y2**2,(t,1*sqrt(3)/3,2*sqrt(3)/3)) \
  +pi*integrate(y3**2,(t,2*sqrt(3)/3,3*sqrt(3)/3)) )
# #########################################################################################################
# 3D作図
def myXYZ2Txt(A):
    return '(' + str(A.x) + ',' + str(A.y) + ',' + str(A.z) + ')'
def myTxtXYZ(A,myWedgei):
    P5x=float(A.x)
    P5y=float(A.y)
    P5z=float(A.z)
    p5 = FreeCAD.Vector(P5x, P5y, P5z)
    myText = Draft.makeText(myWedgei, p5)
    myText.Label = myWedgei
    FreeCADGui.ActiveDocument.ActiveObject.FontSize = '0.05 mm'
def myTxtXYZ_S(*xy_tx):
    for i in range(1,int(len(xy_tx)/2)+1):
        myTxtXYZ(xy_tx[2*i-2],xy_tx[2*i-1]+myXYZ2Txt(xy_tx[2*i-2]) )
def myLine(A,B):
    Ax,Ay,Az=float(A.x),float(A.y),float(A.z)
    Bx,By,Bz=float(B.x),float(B.y),float(B.z)
    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)
def myLine_S(*args):
    for i in range(1,len(args)):
        myLine(args[i-1],args[i])
    return 0
L=1
doc = App.activeDocument()
box = doc.addObject("Part::Box", "myBox")
box.Length = L
box.Width = L
box.Height = L
cosA=(1+1)/(sqrt(3)*sqrt(2))
deg=float(acos(cosA)*180/pi)
myLine(Point(0, 3,0),Point(0,0,3))
myLine(Point(0,-3,0),Point(0,0,3))
box.Placement = App.Placement(App.Vector(0,0,0), App.Rotation(0,-deg,45))
App.ActiveDocument.addObject("App::Origin", "Origin")
App.ActiveDocument.getObject('Origin').Visibility = True
App.ActiveDocument.recompute()
Gui.activeDocument().activeView().viewAxonometric()
Gui.SendMsgToActiveView("ViewFit")
##########################################################################################
import FreeCAD
import Part
import PartDesignGui
from FreeCAD import Base
_=Part.Shell([App.ActiveDocument.myBox.Shape.Face2, App.ActiveDocument.myBox.Shape.Face6, App.ActiveDocument.myBox.Shape.Face3, App.ActiveDocument.myBox.Shape.Face1, App.ActiveDocument.myBox.Shape.Face4, App.ActiveDocument.myBox.Shape.Face5, ])
if _.isNull(): raise RuntimeError('Failed to create shell')
App.ActiveDocument.addObject('Part::Feature','Shell').Shape=_.removeSplitter()
del _
FreeCAD.ActiveDocument.addObject("Part::Revolution","Revolve")
FreeCAD.ActiveDocument.Revolve.Source = FreeCAD.ActiveDocument.Shell
FreeCAD.ActiveDocument.Revolve.Axis = (0.000000000000000,0.000000000000000,1.000000000000000)
FreeCAD.ActiveDocument.Revolve.Base = (0.000000000000000,0.000000000000000,0.000000000000000)
FreeCAD.ActiveDocument.Revolve.Angle = 360.000000000000000
FreeCAD.ActiveDocument.Revolve.Solid = False
FreeCAD.ActiveDocument.Revolve.AxisLink = None
FreeCAD.ActiveDocument.Revolve.Symmetric = False
FreeCADGui.ActiveDocument.Shell.Visibility = False
```