四面体の体積「2023静岡県立大学前期【３】」をsympyとFreeCADでやってみた。

FreeCADのマクロで作図しました。謎が深まるばかりでした。
? tが消えるみたいです。?
(ワイヤーフレームです。ソリッドを勉強中。)

オリジナル

https://mathmathmass.exblog.jp/33069384/

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

https://mathexamtest.web.fc2.com/2023/202311461/2023114610100mj.html#top-0103

# sympyで(オリジナルのやり方)
T氏様の方法を勉強中。

# sympyで(sympy的?安易なやり方)
四面体の体積は、行列式。
?空間の三角形の面積は、外積にしたい。?

```python
from sympy import *
t = Symbol('t', Real=True,positive=True)
def mySimentaiTaiseki(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
def myMenseki3D(O,A,B):
    P=A-O
    Q=B-O
    return Rational(1, 2) * sqrt(P.distance(Point(0, 0, 0)) ** 2 * Q.distance(Point(0, 0, 0)) ** 2 \
                                 - P.dot(Q) ** 2).simplify()
O =Point(0,0,0)
A1=Point(2,1,2)
A2=Point(1,1,1)
A3=Point(0,0,t)
a1=A1-O
a2=A2-O
a3=A3-O
b1=a1/a1.distance((0, 0))
b2=(a2-a2.dot(b1)*b1)/((a2-a2.dot(b1)*b1).distance((0, 0)))
b3=(a3-a3.dot(b1)*b1-a3.dot(b2)*b2)/((a3-a3.dot(b1)*b1-a3.dot(b2)*b2).distance((0, 0)))
print("#(1)",b1.distance((0, 0)),
             b2.distance((0, 0)),
             b1.dot(b2))
print("#(2)",b1.dot(b3),
             b2.dot(b3))
B1=  b1
B2=2*b2
B3=3*b3
print("#(3)",myMenseki3D      (O,B1,B2),
             mySimentaiTaiseki(O,B1,B2,B3))
#(1) 1 1 0
#(2) 0 0
#(3) 1 1
```
# FreeCADのマクロで作図
```python
import FreeCAD
import Part
import Draft
import Mesh
#########################################################################################################
# 計算
from sympy import *
t = Symbol('t', Real=True,positive=True)
def mySimentaiTaiseki(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
def myMenseki3D(O,A,B):
    P=A-O
    Q=B-O
    return Rational(1, 2) * sqrt(P.distance(Point(0, 0, 0)) ** 2 * Q.distance(Point(0, 0, 0)) ** 2 \
                                 - P.dot(Q) ** 2).simplify()
O =Point(0,0,0)
A1=Point(2,1,2)
A2=Point(1,1,1)
A3=Point(0,0,t)
a1=A1-O
a2=A2-O
a3=A3-O
b1=a1/a1.distance((0, 0))
b2=(a2-a2.dot(b1)*b1)/((a2-a2.dot(b1)*b1).distance((0, 0)))
b3=(a3-a3.dot(b1)*b1-a3.dot(b2)*b2)/((a3-a3.dot(b1)*b1-a3.dot(b2)*b2).distance((0, 0)))
print("#(1)",b1.distance((0, 0)),
             b2.distance((0, 0)),
             b1.dot(b2))
print("#(2)",b1.dot(b3),
             b2.dot(b3))
B1=  b1
B2=2*b2
B3=3*b3
print("#(3)",myMenseki3D      (O,B1,B2),
             mySimentaiTaiseki(O,B1,B2,B3))
#(1) 1 1 0
#(2) 0 0
#(3) 1 1
##########################################################################################################
### 作図
A3_1=A3.subs({t:1})
A3_2=A3.subs({t:2})
##########################################################################################################
### 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.2 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]) ) 
    return
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
def myLine_C(*args):
    for i in range(1,len(args)):
        myLine(args[i-1],args[i])
    myLine(args[i],args[0])
    return
myTxtXYZ_S(O   ,"O")
myTxtXYZ_S(A1  ,"A1"    ,A2  ,"A2"    )
myTxtXYZ_S(A3_1,"A3_t=1",A3_2,"A3_t=2")
myTxtXYZ_S(B1,"B1",B2,"B2",B3,"B3")
myLine_C  (A1,A2,A3_1)
myLine_C  (A1,A2,A3_2)
myLine    (O,B1)
myLine    (O,B2)
myLine    (O,B3)
myLine_C  (B1,B2,B3)
#
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")
```

ワイヤーフレームの四面体に見えません。

![0png.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/65b864cc-8f7d-ed19-2604-8300cd0bad4b.png)

三角形A1,A2,A3(t=1)
三角形A1,A2,A3(t=2)
のつもり。文字の傾きを変更していません。XY平面水平です。

![1png.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/5fd0e525-f9bd-868a-4083-3a1d61a11d58.png)



# 参考


https://www.google.com/search?q=%E3%82%B0%E3%83%A9%E3%83%A0%E3%83%BB%E3%82%B7%E3%83%A5%E3%83%9F%E3%83%83%E3%83%88%E3%81%AE%E7%9B%B4%E4%BA%A4%E5%8C%96%E6%B3%95&rlz=1CAUHAM_enJP1038JP1038&oq=%E3%82%B0%E3%83%A9%E3%83%A0%E3%83%BB%E3%82%B7%E3%83%A5%E3%83%9F%E3%83%83%E3%83%88%E3%81%AE%E7%9B%B4%E4%BA%A4%E5%8C%96%E6%B3%95&aqs=chrome.0.69i59j35i39j0i512j69i61.823j0j7&sourceid=chrome&ie=UTF-8

distance(other)

https://docs.sympy.org/latest/modules/geometry/points.html#sympy.geometry.point.Point.distance

S=1/2 |a↑×b↑ + b↑×c↑ + c↑×a↑|
マセマ様の「[ベクトル解析キャンパス・ゼミ 改訂4](https://www.mathema.jp/product/%e3%83%99%e3%82%af%e3%83%88%e3%83%ab%e8%a7%a3%e6%9e%90%e3%82%ad%e3%83%a3%e3%83%b3%e3%83%91%e3%82%b9%e3%83%bb%e3%82%bc%e3%83%9f-%e6%94%b9%e8%a8%827/
)」P52例題10 で見ました。


https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q12101196297

https://qiita.com/aomidro/items/e6d90e25549eb74c5ca5