空間図形 球「2019(H31)年度京都大学前期文系理系共通【5】」をsympyとFreeCADでやってみた。 

半径1の球面上の5点

オリジナル

https://bouseijuku.sakura.ne.jp/2019kyoto-sugaku.pdf#page=6

（問題はこちら）

https://bouseijuku.sakura.ne.jp/nyushisugakukaisetu.html

大学入試数学問題集成＞前期文系理系共通【5】

https://mathexamtest.web.fc2.com/2019/201910541/2019105410100mj.html#top-0106

# sympyだけで
(省略) 

# FreeCADのマクロで
![png.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/07b763a6-efc5-8e55-05f8-5c7b896035a8.png)
変な線がでています。
上の図は、マクロそのままではありません。手を加えています。
transparencyは、CAD操作で60にしました。
```python
import FreeCAD
import Part
import Draft
import Mesh
#########################################################################################################
# 計算
from sympy import *
r1=1
x=Symbol('x', positive=True,real=True)
a=Symbol('a', positive=True,real=True)
a=sqrt(r1*r1-x*x)/sqrt(2)*2
myTaiseki=a*a*(r1+x)*Rational(1,3)
xx=solve(diff(myTaiseki,x),x)[0]
mySubs={x:xx}
print("#",myTaiseki.subs(mySubs))
x=xx
a=sqrt(r1*r1-x*x)/sqrt(2)
print("a",a)
O =Point3D( 0, 0, 0)
A =Point3D( 0, 0, 1)
B1=Point3D(-a, a,-x)
B2=Point3D(-a,-a,-x)
B3=Point3D( a,-a,-x)
B4=Point3D( a, a,-x)
C =Point3D( 0, 0,-x)
##########################################################################################################
### 3D作図
def my_Circle(x,a):
    zaxis = App.Vector(0, 0, 1)
    p5 = App.Vector(0, 0, -float(x))
    place5 = App.Placement(p5, App.Rotation(zaxis, 0))
    circle5 = Draft.make_circle(float(a), placement=place5)
def my_Sphere(my_R):
    sphere = doc.addObject("Part::Sphere", "mySphere2")
    sphere.Radius =   1
    sphere.Angle1 = -90
    sphere.Angle2 =  90
    sphere.Angle3 = 360
    sphere.Placement = App.Placement(App.Vector(0, 0, 0), App.Rotation(0, 90, 0))
    FreeCADGui.getDocument('Unnamed').getObject('mySphere2').Transparency = 90
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.12 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)
def myLine_S(*args):
    for i in range(1,len(args)):
        myLine(args[i-1],args[i])
    return 0
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]) ) 
myTxtXYZ_S(O,"O",A, "A",B1,"B1",B2,"B2",B3,"B3",B4,"B4",C, "C")
myLine_S(B1,B2,B3,B4,B1)
myLine  (A,B1)
myLine  (A,B2)
myLine  (A,B3)
myLine  (A,B4)
myLine  (A,C )
doc = App.activeDocument()
my_Sphere(r1)
my_Circle(x,a*sqrt(2))
App.ActiveDocument.addObject("App::Origin", "Origin")
App.ActiveDocument.getObject('Origin').Visibility = True
App.ActiveDocument.recompute()
Gui.activeDocument().activeView().viewAxonometric()
Gui.SendMsgToActiveView("ViewFit")
```

# 参考
Scripting

https://wiki.freecadweb.org/Part_Sphere#Scripting