0
2

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 5 years have passed since last update.

3D座標の重心を計算する > FeeCADのmacroでやってみたい

Last updated at Posted at 2018-05-14

(元ネタ)3D座標の重心を計算する > Python operator:面倒 | Numpy array:簡単
https://qiita.com/7of9/items/37716cc80f8bc01efa27

fullscript.py
import FreeCAD
import Part
import DraftTools
import Draft
import Mesh
def myTriangle(In_P1x,In_P1y,In_P1z,In_P2x,In_P2y,In_P2z,In_P3x,In_P3y,In_P3z,myLabel):
        P1x,P1y,P1z,P2x,P2y,P2z,P3x,P3y,P3z = float(In_P1x),float(In_P1y),float(In_P1z),float(In_P2x),float(In_P2y),float(In_P2z),float(In_P3x),float(In_P3y),float(In_P3z)
        planarMesh =[
                     [P1x,P1y,P1z],
                     [P2x,P2y,P2z],
                     [P3x,P3y,P3z]
                    ]
        planarMeshObject = Mesh.Mesh(planarMesh)
        Mesh.show(planarMeshObject)
        FreeCAD.getDocument("Unnamed").getObject("Mesh").Label = myLabel
def myTxtXYZ(P5x,P5y,P5z,myStr):
        p5 = FreeCAD.Vector(P5x,P5y,P5z)
        myText = Draft.makeText(myStr,p5) 
        myText.Label = myStr
b =[[-42, -8,60],
    [ 43, 41,60],
    [ 21,-54,60]]
PP0x=round((float(b[0][0])+ float(b[1][0])+ float(b[2][0]))/3,8)
PP0y=round((float(b[0][1])+ float(b[1][1])+ float(b[2][1]))/3,1)
PP0z=round((float(b[0][2])+ float(b[1][2])+ float(b[2][2]))/3,1)
myWedgej='x' + str(PP0x) + ',y' + str(PP0y)+ ',z' + str(PP0z)
myTxtXYZ(PP0x,PP0y,PP0z,'myText ' + myWedgej)
myTriangle(b[0][0],b[0][1],b[0][2], b[1][0],b[1][1],b[1][2], b[2][0],b[2][1],b[2][2],'myMesh ' + myWedgej)

myText x7.33333333,y-7.0,z60.0
教えて下さい。
1.配列の引数のおすすめのページ
2.クラスの引数のおすすめのページ
3.CenterOfMassの使い方
(参考)体積、表面積、重心を求める
https://open-shelf.appspot.com/FreeCAD/3.html
よろしくお願いします。

0
2
1

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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?