空間ベクトル「公立小松大学2020年第2問」をsympyとFreeCADでやってみた。 

オリジナル
A(0,1,3),B(2,0,1),C(1,2,0)...線分BCをにt:(t-1)に内分する点を

https://mathmathmass.exblog.jp/32131961/

大学入試数学問題集成＞

https://mathexamtest.web.fc2.com/2020/202011371/2020113710100mj.html#top-0102

公式ホームページ＞問題、出題意図

https://www.komatsu-u.ac.jp/common/images/dc_2020-zenki-system-m.pdf#page=2

https://www.komatsu-u.ac.jp/common/images/dc_2020-zenki-system-m-intention.pdf 

https://www.komatsu-u.ac.jp/admission/disclosure/2020.html



# sympyで
```python
from sympy import *
var('t')
A=Point3D(0,1,3)
B=Point3D(2,0,1)
C=Point3D(1,2,0)
P=B+t*(C-B)
print("#(1)",P-A)
Z0=Plane(Point3D(0,0,0), normal_vector=(0,0,1))
AP=Line(P,A)
Q=Plane(Point3D(0,0,0), normal_vector=(0,0,1)).intersection(Line(A,P))[0]
print("#(2)",Q.x.simplify(),Q.y.simplify(),Q.z.simplify())
ans=solve((Q-A).dot(C-B),t)[0]
print("#(3)",ans,ans in Interval(0, 1))
print("#(3)",Q.subs({t:ans}))
#(1) Point3D(2 - t, 2*t - 1, -t - 2)
#(2) 3*(2 - t)/(t + 2) (7*t - 1)/(t + 2) 0
#(3) 1/3 True
#(3) Point3D(15/7, 4/7, 0)
```
# FreeCADのマクロで
上のsympy計算に、FreeCAD作図を追加しました。
```python
import FreeCAD
import Part
import Draft
import Mesh
#########################################################################################################
# 計算
from sympy import *
var('t')
A=Point3D(0,1,3)
B=Point3D(2,0,1)
C=Point3D(1,2,0)
P=B+t*(C-B)
print("#(1)",P-A)
Z0=Plane(Point3D(0,0,0), normal_vector=(0,0,1))
AP=Line(P,A)
Q=Plane(Point3D(0,0,0), normal_vector=(0,0,1)).intersection(Line(A,P))[0]
print("#(2)",Q.x.simplify(),Q.y.simplify(),Q.z.simplify())
ans=solve((Q-A).dot(C-B),t)[0]
print("#(3)",ans,ans in Interval(0, 1))
Q=Q.subs({t:ans})
print("#(3)",Q)
#(1) Point3D(2 - t, 2*t - 1, -t - 2)
#(2) 3*(2 - t)/(t + 2) (7*t - 1)/(t + 2) 0
#(3) 1/3 True
#(3) Point3D(15/7, 4/7, 0)
P=P.subs({t:ans})
#########################################################################################################
# 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.5 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(Q,"Q"+myXYZ2Txt(Q))
myLine(B,C)
myLine(A,Q)
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")
```
点Qが、XY平面上に見えませんでした。

![png.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/82fc7ff7-7c87-31f2-4f70-bfabc6c2ff8c.png)


# 参考

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