四面体の体積「2021 慶応義塾大学 薬 数学(7)」をWolframAlphaとsympyとFreeCADでやってみた。

...四面体ABCDの体積は[シ]である。...

オリジナル

https://kamelink.com/blog/2022/12/17/9-6-21-keiodai-kusuri-1-7/

解答

https://kaisoku.kawai-juku.ac.jp/nyushi/honshi/21/k18-21a.pdf#page=5

~~https://www2.sundai.ac.jp/sokuhou/2021/keo1_suu_1.pdf#page=4~~

上と同じです。大学入試数学問題集成＞【１】

https://mathexamtest.web.fc2.com/2021/202113338/2021133380100mj.html#top-0107


# WolframAlpha で
視覚表示あります。グラフです。

https://www.wolframalpha.com/input/?i=tetrahedron%E3%80%80%280%2C-2%2C2%29%2C%280%2C2%2C2%29%2C%282%2C0%2C-2%29%2C%28-2%2C0%2C-2%29&lang=ja

特性
独立した辺の長さ | (4 | 2 sqrt(6) | 2 sqrt(6) | 2 sqrt(6) | 2 sqrt(6) | 4)≈(4 | 4.89898 | 4.89898 | 4.89898 | 4.89898 | 4)
体積 | 32/3≈10.6667

tetrahedron (0,-2,2),(0,2,2),(2,0,-2),(-2,0,-2)　はできましたが、
四面体 　　(0,-2,2),(0,2,2),(2,0,-2),(-2,0,-2)　はできませんでした。

https://www.wolframalpha.com/input/?i=%E5%9B%9B%E9%9D%A2%E4%BD%93+%280%2C-2%2C2%29%2C%280%2C2%2C2%29%2C%282%2C0%2C-2%29%2C%28-2%2C0%2C-2%29&lang=ja


# Pycharmで
後から？代入。.subsです。

```python
from sympy import *
var('xA,yA,zA,xB,yB,zB,xC,yC,zC,xD,yD,zD')
def myTaiseki(PTO,PTA,PTB,PTC):
    return Matrix([[PTA.x-PTO.x, PTA.y-PTO.y, PTA.z-PTO.z],
                   [PTB.x-PTO.x, PTB.y-PTO.y, PTB.z-PTO.z],
                   [PTC.x-PTO.x, PTC.y-PTO.y, PTC.z-PTO.z]]
                  ).det()/6
PA=Point3D(xA,yA,zA)
PB=Point3D(xB,yB,zB)
PC=Point3D(xC,yC,zC)
PD=Point3D(xD,yD,zD)
mySubs={
        xA: 0,yA:-2,zA: 2,
        xB: 0,yB: 2,zB: 2,
        xC: 2,yC: 0,zC:-2,
        xD:-2,yD: 0,zD:-2
        }
print("#",myTaiseki(PA,PB,PC,PD))
print("#",myTaiseki(PA,PB,PC,PD).subs(mySubs))
# -xA*yB*zC/6 + xA*yB*zD/6 + xA*yC*zB/6 - xA*yC*zD/6 - xA*yD*zB/6 + xA*yD*zC/6 + xB*yA*zC/6 - xB*yA*zD/6 - xB*yC*zA/6 + xB*yC*zD/6 + xB*yD*zA/6 - xB*yD*zC/6 - xC*yA*zB/6 + xC*yA*zD/6 + xC*yB*zA/6 - xC*yB*zD/6 - xC*yD*zA/6 + xC*yD*zB/6 + xD*yA*zB/6 - xD*yA*zC/6 - xD*yB*zA/6 + xD*yB*zC/6 + xD*yC*zA/6 - xD*yC*zB/6
# 32/3
```


# 上のsympy計算に、FreeCAD作図を追加しました。
ワイヤーフレームで
```python
import FreeCAD
import Part
import Draft
import Mesh
#########################################################################################################
# 計算
from sympy import *
var('xA,yA,zA,xB,yB,zB,xC,yC,zC,xD,yD,zD')
def myTaiseki(PTO,PTA,PTB,PTC):
    return Matrix([[PTA.x-PTO.x, PTA.y-PTO.y, PTA.z-PTO.z],
                   [PTB.x-PTO.x, PTB.y-PTO.y, PTB.z-PTO.z],
                   [PTC.x-PTO.x, PTC.y-PTO.y, PTC.z-PTO.z]]
                  ).det()/6
PA=Point3D(xA,yA,zA)
PB=Point3D(xB,yB,zB)
PC=Point3D(xC,yC,zC)
PD=Point3D(xD,yD,zD)
mySubs={
        xA: 0,yA:-2,zA: 2,
        xB: 0,yB: 2,zB: 2,
        xC: 2,yC: 0,zC:-2,
        xD:-2,yD: 0,zD:-2
        }
print("#",myTaiseki(PA,PB,PC,PD))
print("#",myTaiseki(PA,PB,PC,PD).subs(mySubs))
# -xA*yB*zC/6 + xA*yB*zD/6 + xA*yC*zB/6 - xA*yC*zD/6 - xA*yD*zB/6 + xA*yD*zC/6 + xB*yA*zC/6 - xB*yA*zD/6 - xB*yC*zA/6 + xB*yC*zD/6 + xB*yD*zA/6 - xB*yD*zC/6 - xC*yA*zB/6 + xC*yA*zD/6 + xC*yB*zA/6 - xC*yB*zD/6 - xC*yD*zA/6 + xC*yD*zB/6 + xD*yA*zB/6 - xD*yA*zC/6 - xD*yB*zA/6 + xD*yB*zC/6 + xD*yC*zA/6 - xD*yC*zB/6
# 32/3
#########################################################################################################
# 代入(計算箇所でSubsを使っていました。)
PA=PA.subs(mySubs)
PB=PB.subs(mySubs)
PC=PC.subs(mySubs)
PD=PD.subs(mySubs)
#########################################################################################################
# 3D作図
def myXYZ2Txt(A):
    return '(' + str(A.x) + ',' + str(A.y) + ',' + str(A.z) + ')'
def myTxt_XYZ(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.3 mm'
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)
myTxt_XYZ(PA,"A"+myXYZ2Txt(PA))
myTxt_XYZ(PB,"B"+myXYZ2Txt(PB))
myTxt_XYZ(PC,"C"+myXYZ2Txt(PC))
myTxt_XYZ(PD,"D"+myXYZ2Txt(PD))
doc = App.activeDocument()
myLine(PA,PB)
myLine(PA,PC)
myLine(PA,PD)
myLine(PB,PC)
myLine(PC,PD)
myLine(PD,PB)
App.ActiveDocument.addObject("App::Origin", "Origin")
App.ActiveDocument.recompute()
Gui.activeDocument().activeView().viewAxonometric()
Gui.SendMsgToActiveView("ViewFit")
```

![origin-noshow.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/e341079b-df17-5e4b-49b8-4d7b13480e60.png)
![origin-show.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/3b37868b-46db-f14d-3c2f-b9f5888cdcdd.png)


# 参考
CASIO＞生活や実務に役立つ高精度計算サイト

https://keisan.casio.jp/exec/system/1202458218