問題文は2次元ですが、3次元FreeCADのマクロで、XY平面上に作図しました。
オリジナル
上と同じです。大学入試数学問題集成>【2】テキスト
sympyで(オリジナルのやり方)
数学入試問題 様の方法を勉強中。
T氏様の方法を勉強中。
sympyで(sympy的?安易なやり方)
・選択の方法を教えて下さい。
・代入もいい方法を教えて下さい。
from sympy import *
a,b,c,d,e,f=symbols('a b c d e f',real=True)
def myMenseki2D(O,A,B):
P=A-O
Q=B-O
return Rational(1, 2) * sqrt(P.distance(Point(0, 0)) ** 2 * Q.distance(Point(0, 0)) ** 2 \
- P.dot(Q) ** 2).simplify()
OA=BC=5
OB=AC=7
OC=AB=8
e1=Point(1,0)
e2=Point(0,1)
O=Point(0,0)
A=Point(a,b)
B=Point(c,d)
C=Point(e,f)
u=A-O
v=B-A
w=C-B
ans=solve([
Eq(u.x ,-e1.x ),
Eq(u.y ,-e1.y ),
Eq(v.dot(e1) ,4 ),
Eq(w.dot(e1) ,8 ),
Eq(v.distance(O),2*sqrt(5)),
Eq(w.distance(O),8*sqrt(2)),
#LessThan( v.x*e1.x+v.y*e1.y,0),
#LessThan(0,w.x*e2.x+w.y*e2.y )
],[a,b,c,d,e,f]
)[1]
A=Point(ans[0],ans[1])
B=Point(ans[2],ans[3])
C=Point(ans[4],ans[5])
print("#(1)",A,B,C)
print("#(2)",Circle(A,B,C).equation().expand())
P=Circle(A,B,C).center
print("#(3)",myMenseki2D(A,B,C)/myMenseki2D(A,B,P))
#(1) Point2D(-1, 0) Point2D(3, -2) Point2D(11, 6)
#(2) x**2 - 8*x + y**2 - 10*y - 9
#(3) 8/5
①私の環境は,pycharmです。
②よく聞くのは、Jupyterです。
③web上で、上記のソースを「SymPy Live shell」に、。
黒背景の右上に、マウスを移動すると、コピーマークが発生します。
FreeCADのマクロで作図
import FreeCAD
import Part
import DraftTools
import Draft
import Mesh
############################################################################
# 計算
from sympy import *
a,b,c,d,e,f=symbols('a b c d e f',real=True)
def myMenseki2D(O,A,B):
P=A-O
Q=B-O
return Rational(1, 2) * sqrt(P.distance(Point(0, 0)) ** 2 * Q.distance(Point(0, 0)) ** 2 \
- P.dot(Q) ** 2).simplify()
OA=BC=5
OB=AC=7
OC=AB=8
e1=Point(1,0)
e2=Point(0,1)
O=Point(0,0)
A=Point(a,b)
B=Point(c,d)
C=Point(e,f)
u=A-O
v=B-A
w=C-B
ans=solve([
Eq(u.x ,-e1.x ),
Eq(u.y ,-e1.y ),
Eq(v.dot(e1) ,4 ),
Eq(w.dot(e1) ,8 ),
Eq(v.distance(O),2*sqrt(5)),
Eq(w.distance(O),8*sqrt(2)),
#LessThan( v.x*e1.x+v.y*e1.y,0),
#LessThan(0,w.x*e2.x+w.y*e2.y )
],[a,b,c,d,e,f]
)[1]
A=Point(ans[0],ans[1])
B=Point(ans[2],ans[3])
C=Point(ans[4],ans[5])
print("#(1)",A,B,C)
print("#(2)",Circle(A,B,C).equation().expand())
P=Circle(A,B,C).center
print("#(3)",myMenseki2D(A,B,C)/myMenseki2D(A,B,P))
############################################################################
r=Circle(A,B,C).radius
############################################################################
# 3D作図 z=0 XY平面に作図しました。
############################################################################
# 円の作図 FrecCADのdocより
# https://wiki.freecad.org/Macro_Circle
def 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(x,y,r):
circle(x=float(x),y=float(y),z=0.0,
radius=float(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 myXYZ2Txt_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 = '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 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
myTxtXYZ_S_2D(O,"O",A,"A",B,"B",C,"C")
myTxtXYZ_S_2D(P,"P")
myLine_C_2D (A,B,C)
myLine_C_2D (A,B,P)
myCircle_2D (P.x,P.y,r)
#
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")```
isometric方向?です。
上空から?です。
参考
以下、いつもの?おすすめです。