空間図形「2021年度 京都大・理系数学 問1(1)」をsympyとFreeCADでやってみた。

3 点 A(1, 0, 0)，B(0, −1, 0)，C(0, 0, 2) を通る平面 α

オリジナル

https://www.densu.jp/kyoto/21kyotospass.pdf

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

https://mathexamtest.web.fc2.com/2021/202110541/2021105410100mj.html#top-0107

# Pycharmで(projection)

SymPy Liveだとエラーがでます。
AttributeError: 'Point3D' object has no attribute 'as_coeff_Mul'

https://live.sympy.org/

```python
from sympy import *
A=Point3D(1, 0,0)
B=Point3D(0,-1,0)
C=Point3D(0, 0,2)
P=Point3D(1, 1,1)
print("#",P+2*(Plane(A,B,C).projection(P)-P))
# Point3D(13/9, 5/9, 11/9)
```
# Pycharmで(solve)
kaisoku.kawai-juku.ac.jpにちかいかもしれない。
SymPy Liveでできます。

以下のソースコードを貼り付けて、Evaluateです。

https://live.sympy.org/

```python
from sympy import *
var('m')
def myPtoM(myPoint3D):
    return Matrix([myPoint3D.x,myPoint3D.y,myPoint3D.z])
def myHtoP(myHairetu):
    return Point3D(myHairetu[0],myHairetu[1],myHairetu[2])
def myDot(P1,P2):
    return myPtoM(P1).dot(myPtoM(P2))
A=Point3D(1, 0,0)
B=Point3D(0,-1,0)
C=Point3D(0, 0,2)
P=Point3D(1, 1,1)
vn=myHtoP(Plane(A,B,C).normal_vector)
print("#",P+2*solve(myDot(vn,A-(P+m*vn)),m)[0]*vn)
# Point3D(13/9, 5/9, 11/9)
```

# sympy計算とFreeCAD作図で

```python
import FreeCAD
import Part
import Draft
import Mesh
#########################################################################################################
# 計算
from sympy import *
A=Point3D(1, 0,0)
B=Point3D(0,-1,0)
C=Point3D(0, 0,2)
P=Point3D(1, 1,1)
M=     Plane(A,B,C).projection(P)
Q=P+2*(Plane(A,B,C).projection(P)-P)
print("#",Q)
#########################################################################################################
# 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.1 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(A,"A"+myXYZ2Txt(A))
myTxt_XYZ(B,"B"+myXYZ2Txt(B))
myTxt_XYZ(C,"C"+myXYZ2Txt(C))
myTxt_XYZ(P,"P"+myXYZ2Txt(P))
myTxt_XYZ(M,"M"+myXYZ2Txt(M))
myTxt_XYZ(Q,"Q"+myXYZ2Txt(Q))
doc = App.activeDocument()
myLine(A,B)
myLine(B,C)
myLine(C,A)
myLine(P,Q)
#
myLine(A,M)
myLine(M,C)
App.ActiveDocument.addObject("App::Origin", "Origin")
App.ActiveDocument.getObject('Origin').Visibility = True
App.ActiveDocument.recompute()
Gui.activeDocument().activeView().viewAxonometric()
Gui.SendMsgToActiveView("ViewFit")
```
ABC平面に見えませんね。

![png.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/da42ac44-1934-6eeb-a032-52aa7b9d8fe9.png)


# 参考

https://manabitimes.jp/math/1685

~~代ゼミ https://sokuho.yozemi.ac.jp/sokuho/k_mondaitokaitou/2/kaitou/kaitou/1331504_5346.html~~

~~代ゼミhttps://kaisoku.kawai-juku.ac.jp/nyushi/honshi/21/k01-21a.pdf#page=1~~