【问题标题】:Fundamental misunderstanding of translation and rotation in PythonOCC (OpenCascade)PythonOCC(OpenCascade)中平移和旋转的基本误区
【发布时间】:2018-05-30 17:05:11
【问题描述】:

也许这将有助于其他尝试通过教程/文档/stackoverflow 学习的人。

如何旋转或平移 TopoDS_Shape(或任何对象),提供坐标、角度和轴?例如:如果我的零件位于 (5.0, 1.0, 0.0),我可以将其移动到 (0.0, 0.0, 0.0) 吗?还是让它面临一个新的方向?

尝试过的方法(不包括我认为不重要的代码)。我试图包括一些我大部分时间都花在上面的东西。不记得我所做的所有其他尝试。也许有 PythonOCC 或 OpenCascade 经验的人可以看出我哪里出错了。

display, start_display, add_menu, add_function_to_menu = init_display()

aResShape = openFile.open(fileToOpen) #RETURNS SHAPE FROM STEP FILE

aResShape.Orientable(True)

#EXAMPLE
aResShape.Location().Transformation().SetRotation(gp_Quaternion(1., 1., 0., 1.))

#EXAMPLE
aResShape.Location().Transformation().SetTransformation(a,b)

#EXAMPLE
aResShape.Move(TopLoc_Location(gp_Trsf( gp_Trsf2d(1., 0.) )))

#EXAMPLE
aResShape.Reverse()

#EXAMPLE
p1 = gp_Pnt(700., 10., 80.)
d1 = gp_Dir(50., 50., 60.)
a = gp_Ax3(p1, d1)

p2 = gp_Pnt(2., 3., 4.)
d2 = gp_Dir(4., 5., 6.)
b = gp_Ax3(p2, d2)
print(aResShape.Location().Transformation().Transforms())
aResShape.Location().Transformation().SetTransformation(a,b)
print(aResShape.Location().Transformation().Transforms()) #RETURNS SAME VALUES

#EXAMPLE (TRYING TO SEE WHAT WORKS)
transform = gp_Trsf
transform.SetRotation(
    gp_Ax1(
        gp_Pnt(0.,0.,0.),
        gp_Dir(0.,0.,1.)
    ),
    1.570796
)
print(transform)


display.DisplayShape(aResShape, color='Black', update=True)
display.FitAll()
display.SetModeWireFrame()
start_display()

有时我会收到这样的错误:

NotImplementedError: Wrong number or type of arguments for overloaded function 'new_gp_Trsf2d'.
  Possible C/C++ prototypes are:
    gp_Trsf2d::gp_Trsf2d()
    gp_Trsf2d::gp_Trsf2d(gp_Trsf const &)

但大多数时候我什么也得不到,而且显示中的形状也没有改变。

在这里度过了几天: https://cdn.rawgit.com/tpaviot/pythonocc-core/804f7f3/doc/apidoc/0.18.1/index.html

https://dev.opencascade.org/doc/refman/html/index.html

https://github.com/tpaviot/pythonocc-demos/tree/master/examples

所以我知道我认为要传递哪些函数,但似乎没有任何结果。

也许显示屏根本没有向我显示实际发生的变化?

我之前问了一个不同的 PythonOCC 问题 (pythonOCC set default units to inches),但我认为我真的只是缺少一些基本的东西。

谁能想到我为什么没有做出任何真正的改变?感谢您的宝贵时间!

【问题讨论】:

    标签: python step opencascade


    【解决方案1】:

    我在 C++ 中使用 Open Cascade,BRepBuilderAPI_Transform(const TopoDS_Shape &S, const gp_Trsf &T, const Standard_Boolean Copy=Standard_False) 正在实现转换。看: https://www.opencascade.com/doc/occt-6.9.1/refman/html/class_b_rep_builder_a_p_i___transform.html

    我是这样用的:

    gp_Trsf trsf;
    trsf.SetTransformation(gp_Quaternion(gp_Mat(gp_XYZ(d.x1, d.y1, d.z1), gp_XYZ(d.x2, d.y2, d.z2), gp_XYZ(d.x1, d.y1, d.z1).Crossed(gp_XYZ(d.x2, d.y2, d.z2)))), gp_Vec(d.x, d.y, d.z));                               
    *d.shape = BRepBuilderAPI_Transform(*d.shape, trsf, true);
    

    【讨论】:

      猜你喜欢
      • 2017-09-27
      • 1970-01-01
      • 2016-05-11
      • 2013-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多