0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

空間図形「21年 東京薬大 薬 2(1)」をsympyとFreeCADでやってみた。

Last updated at Posted at 2022-12-12

...3点A(−1,2,2),B(1,4,2),C(0,4,3) ともう1点P ....
オリジナル

上と同じです。大学入試数学問題集成>
未登録

sympyで(オリジナルのやり方)

勉強中

sympyで(sympy的?安易なやり方)

10行でした。

from sympy import *
var('x y')
O,A,B,C=map(Point,([0,0,0],[-1,2,2],[1,4,2],[0,4,3]))
P=(A-O)+x*(B-A)+y*(C-A)
OPAB=Eq((P-O).dot(B-A),0).simplify()
print("#(1)",OPAB)
OPAC=Eq((P-O).dot(C-A),0)
ans=solve([OPAB,OPAC],[x,y])
print("#(2)",ans)
print("#(3)",O.distance(P).subs({x:ans[x],y:ans[y]}))
#(1) Eq(4*x + 3*y, -1)
#(2) {x: 3/2, y: -7/3}
#(3) sqrt(3)/3

以下の、on line sympyで、上記のソースコードを貼り付けて実行できました。私の環境は,pycharmです。 

FreeCADのマクロで

マクロからsympyを使っています。
?点Pが△ABC平面上に見えません。?
FreeCADのDatumPlaneの使い方を教えて下さい。
png.png

import FreeCAD
import Part
import Draft
import Mesh
#########################################################################################################
from sympy import *
var('x y')
O,A,B,C=map(Point,([0,0,0],[-1,2,2],[1,4,2],[0,4,3]))
P=(A-O)+x*(B-A)+y*(C-A)
OPAB=Eq((P-O).dot(B-A),0).simplify()
print("#(1)",OPAB)
OPAC=Eq((P-O).dot(C-A),0)
ans=solve([OPAB,OPAC],[x,y])
print("#(2)",ans)
print("#(3)",O.distance(P).subs({x:ans[x],y:ans[y]}))
#########################################################################################################
P=P.subs({x:ans[x],y:ans[y]})
#########################################################################################################
# 3D作図
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.2 mm'
    return
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]) )
    return
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)
    return
def myLine_S(*args):
    for i in range(1,len(args)):
        myLine(args[i-1],args[i])
    return
myTxtXYZ_S(O,"O",A,"A",B,"B",C,"C",P,"P")
myLine    (A,B)
myLine    (A,C)
myLine_S  (O,P,A)
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")
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?