半円の中に直角二等辺三角形「高校入試チャレンジ問題 CEの長さを求めよ」をsympyとFreeCADでやってみたい。

・**ｘは右側と左側にでました。同じ値です。**
　>直角になって、
・私は、方べきの定理で確認していません。
・solvesetのIntervalは、openにしていません。
　いくらにしたら良かったでしょうか？
・相変わらず怪しいsubsです。
・私は、半円の作図ははじめてかも。

# オリジナル
・YUUU0123 様 (0:00〜4:40) 

https://youtu.be/mEbtlhc8r1w

# sympyで(オリジナル 様の方法を参考に)
・私は、方べきの定理を勉強中です。
```python
from sympy import *
var('m,y,S,x',real=True,poitive=True)
r,Fx=12,-8
eq1=Eq(m*y,4*20)
eq2=Eq(2*S,m*y*Rational(1,2))
sol=solve([eq1,eq2],[S,m,y])
print("#",sol[0][0])
print("#",solve(Eq(8*x*Rational(1,2),sol[0][0]),x)[0])
# 20
# 5
```

# sympyで(いつもの方法で)
(省略)ver0.1 t=∠COB.△FDCのsolveで。
(省略)ver0.2 t=∠DOB.△FCDのsolveで。
(省略)ver0.3 t=∠COB.△FCDのsolvesetで。
**ver0.4 t=∠DOB.△FDCのsolvesetで。**
＞Solveset
https://docs.sympy.org/latest/modules/solvers/solveset.html
＞Denests sqrts in an expression that contain other square roots if possible, otherwise returns the expr unchanged. This is based on the algorithms of [1].
https://docs.sympy.org/latest/modules/simplify/simplify.html#sympy.simplify.sqrtdenest.sqrtdenest
```python
# ver0.4 t=∠DOB.△FDCのsolvesetで。 
from sympy import *
var('t',real=True,poitive=True)
r,Fx=12,-8
F,D=map(Point,[(Fx,0,),(r*cos(t),r*sin(t))])
C=D+(D-F).rotate(-pi/2)
# 
sol=solveset(Eq(C.x**2+C.y**2,r**2),t,Interval(0,pi))
print("#",float(deg(sol.args[0])),sol.args[0])
print("#",float(deg(sol.args[1])),sol.args[1])
C0=C.subs({t:sol.args[0]})
C1=C.subs({t:sol.args[1]})
# 
rep0={(2*sqrt( 13*sqrt(119) + 144)):sqrtdenest(2*sqrt( 13*sqrt(119) + 144))}
rep1={(2*sqrt(-13*sqrt(119) + 144)):sqrtdenest(2*sqrt(-13*sqrt(119) + 144))}
x=C0.y.simplify().subs(rep0).simplify()
C0=Point(sqrt(r**2-x**2),x)
x=C1.y.simplify().subs(rep1).simplify()
C1=Point(-sqrt(r**2-x**2),x)
print("#",C0)
print("#",C1)
# 94.99892174378387 atan((sqrt(119) + 13)/(-13 + sqrt(119))) + pi
# 175.00107825621612 atan((13 - sqrt(119))/(-13 - sqrt(119))) + pi
# Point2D(sqrt(119), 5)
# Point2D(-sqrt(119), 5)
```
# FreeCADのマクロで作図
```python
import FreeCAD
import Part
import DraftTools
import Draft
import Mesh
############################################################################
# ver0.4 t=∠DOB.△FDCのsolvesetで。 
from sympy import *
var('t',real=True,poitive=True)
r,Fx=12,-8
F,D=map(Point,[(Fx,0,),(r*cos(t),r*sin(t))])
C=D+(D-F).rotate(-pi/2)
# 
sol=solveset(Eq(C.x**2+C.y**2,r**2),t,Interval(0,pi))
print("#",float(deg(sol.args[0])),sol.args[0])
print("#",float(deg(sol.args[1])),sol.args[1])
C0=C.subs({t:sol.args[0]})
C1=C.subs({t:sol.args[1]})
# 
rep0={(2*sqrt( 13*sqrt(119) + 144)):sqrtdenest(2*sqrt( 13*sqrt(119) + 144))}
rep1={(2*sqrt(-13*sqrt(119) + 144)):sqrtdenest(2*sqrt(-13*sqrt(119) + 144))}
x=C0.y.simplify().subs(rep0).simplify()
C0=Point(sqrt(r**2-x**2),x)
x=C1.y.simplify().subs(rep1).simplify()
C1=Point(-sqrt(r**2-x**2),x)
print("#",C0)
print("#",C1)
####################################################
O,A,B =map(Point,[(0,0),(-r,0),(r,0)])
D0=F.midpoint(C0)+C0.distance(F)*Rational(1,2)*(C0-F.midpoint(C0)).unit.rotate(pi/2)
E0=Point(C0.x,0)
D1=F.midpoint(C1)+C1.distance(F)*Rational(1,2)*(C1-F.midpoint(C1)).unit.rotate(pi/2)
E1=Point(C1.x,0)
############################################################################
# 3D作図 z=0 XY平面に作図しました。
############################################################################
# 円の作図　FrecCADのdocより
# https://wiki.freecad.org/Macro_Circle
def Freecad3D_circle(x=0.0,y=0.0,z=0.0,radius=0.0,diameter=0.0,circumference=0.0,area=0.0,startangle=0.0,endangle=0.0,arc=0.0,anglecenter=0.0,cord=0.0,arrow=0.0,center=0,placemObject=""):
    from math import sqrt, pi
    if placemObject == "":
        pl = FreeCAD.Placement()
        pl.Rotation = FreeCADGui.ActiveDocument.ActiveView.getCameraOrientation()   
        pl.Base = FreeCAD.Vector(x,y,z)
    else:
        pl = FreeCAD.Placement()
        pl = placemObject                                   # placement imposted
    if diameter != 0:                                           # with diameter
        radius = diameter / 2.0
    elif circumference != 0:                               # with circumference
        radius = (circumference / pi) / 2.0
    elif area != 0:                                                 # with area
        radius =  sqrt((area / pi))
    elif (cord != 0) and (arrow != 0):                     # with cord and arrow
        radius = ((arrow**2) + (cord**2) / 4.0) / (arrow*2) 
    elif (arc != 0) and (anglecenter != 0):                # with arc and anglecenter central in degrees
        radius = ((360/anglecenter)*arc) / pi/2.0
        if endangle != 0:
            startangle  = endangle - anglecenter
        endangle   = anglecenter + startangle
        startangle  = endangle - anglecenter
    if radius != 0:
        try:
            Draft.makeCircle(radius,placement=pl,face=False,startangle=startangle,endangle=endangle,support=None)
            if center != 0:
                x=pl.Base.x
                y=pl.Base.y
                z=pl.Base.z
                Draft.makePoint(x,y,z)
        except Exception:
            App.Console.PrintError("Unexpected keyword argument" + "\n")
        App.ActiveDocument.recompute()
    else:
        App.Console.PrintMessage("Unexpected keyword argument" + "\n")
        App.Console.PrintMessage("circle(x,y,z,radius,diameter,circumference,area,startangle,endangle,[arc,anglecenter],[cord,arrow],center,placemObject)" + "\n")
        App.Console.PrintMessage("circle(radius=10.0,placemObject=App.Placement(App.Vector(11,20,30), App.Rotation(30,40,0), App.Vector(0,0,0)))" + "\n")
    return
def myCircle_2D(myCi):
    x=myCi.center.x
    y=myCi.center.y
    r=myCi.radius
    Freecad3D_circle(
           x=float(x),y=float(y),z=0.0,
           radius=float(abs(r)),
           center=1,
           placemObject=App.Placement(App.Vector(float(x),float(y),0),
           App.Rotation(0,0,0),App.Vector(0,0,0)))
    return
def myCircle_Ogigata_2D(myCi,myStAngle,myEndAngle):
    x=myCi.center.x
    y=myCi.center.y
    r=myCi.radius
    Freecad3D_circle(
           x=float(x),y=float(y),z=0.0,
           radius=float(abs(r)),
           startangle=myStAngle,
           endangle=myEndAngle,
           center=1,
           placemObject=App.Placement(App.Vector(float(x),float(y),0),
           App.Rotation(0,0,0),App.Vector(0,0,0)))
 #  myLine_S_2D(Point(x,y),Point(x+r*cos(rad(myStAngle)), y+r*sin(rad(myStAngle))))
 #  myLine_S_2D(Point(x,y),Point(x+r*cos(rad(myEndAngle)), y+r*sin(rad(myEndAngle))))
    return
def myXYZ2Txt_2D(A):
    return ""
def myXYZ2Txt_XY_2D(A):
    return '(' + str(A.x) + ',' + str(A.y) +  ')'
def myTxtXYZ_2D(A,myWedgei):
    P5x=float(A.x)
    P5y=float(A.y)
    P5z=0.0
    p5 = FreeCAD.Vector(P5x, P5y, P5z)
    myText = Draft.makeText(myWedgei, p5)
    myText.Label = myWedgei
    FreeCADGui.ActiveDocument.ActiveObject.FontSize = '1.0 mm'
    # FreeCADGui.ActiveDocument.ActiveObject.FontSize = '0.5 mm'
    return
def myTxtXYZ_S_2D(*xy_tx):
    for i in range(1,int(len(xy_tx)/2)+1):
        myTxtXYZ_2D(xy_tx[2*i-2],xy_tx[2*i-1]+myXYZ2Txt_2D(xy_tx[2*i-2]) )
    return
def myTxtXYZ_XY_S_2D(*xy_tx):
    for i in range(1,int(len(xy_tx)/2)+1):
        myTxtXYZ_2D(xy_tx[2*i-2],xy_tx[2*i-1]+myXYZ2Txt_XY_2D(xy_tx[2*i-2]) )
    return
def myLine_2D(A,B):
    Ax,Ay,Az=float(A.x),float(A.y),0.0
    Bx,By,Bz=float(B.x),float(B.y),0.0
    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)
    return
def myLine_S_2D(*args):
    for i in range(1,len(args)):
        myLine_2D(args[i-1],args[i])
    return
def myLine_C_2D(*args):
    for i in range(1,len(args)):
        myLine_2D(args[i-1],args[i])
    myLine_2D(args[i],args[0])
    return
def myLine_H_2D(*args):
    for i in range(1,len(args)):
        myLine_2D(args[0],args[i])
    return
##################################################################################
myCircle_Ogigata_2D(Circle(O,r),0,180)
myLine_S_2D        (A,F,O,B)  
myLine_S_2D        (F,D0,C0,E0)
myLine_S_2D        (F,D1,C1,E1)
myTxtXYZ_S_2D      (A,"A",F,"F",O,"O",B,"B")
myTxtXYZ_S_2D      (D0,"D0",C0,"C0",E0,"E0")
myTxtXYZ_S_2D      (D1,"D1",E1,"E1")
myTxtXYZ_S_2D      (D0,"D0",E0,"E0")
myTxtXYZ_XY_S_2D   (C0,"C0")
myTxtXYZ_XY_S_2D   (C1,"C1")
####################################################################################
doc = App.activeDocument()
#App.ActiveDocument.addObject("App::Origin", "Origin")
#App.ActiveDocumen!t.getObject('Origin').Visibility = True
App.ActiveDocument.recompute()
Gui.activeDocument().activeView().viewAxonometric()
Gui.SendMsgToActiveView("ViewFit")
```
isometric方向?です。(省略)
拡大図

![2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/b4dad986-204e-f1d6-09a6-a9ed5051e82f.png)

拡大図(CADの操作で寸法線を追加)
・点C0と点C1があります。
・点C0と点C1のみ、座標表示しました。
・(青色の)角度寸法は、ニセモノです。Part＞計測＞角度計算 です。
・角度寸法の表示は、まだ勉強中です。
![3.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109698/0bf5fc75-fda1-38eb-60b5-292ead451db3.png)


# いつもの? sympyの実行環境と 参考のおすすめです。
[(テンプレート)](https://qiita.com/mrrclb48z/items/00dd08b0317069be9342)

・以下ができたら、助かります。指定と全部です

https://qiita.com/mrrclb48z/items/555d85face87552c34fb

https://qiita.com/mrrclb48z/items/5f57eac92aaca30e85c0


# いつもと違うおすすめです。