也许这会帮助其他试图通过教程/文档/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),但我想我真的遗漏了一些基本的东西。
有人能想到为什么我不能做出任何真正的改变吗?耽误您时间,实在对不起!
发布于 2018-11-17 07:34:48
我将Open Cascade与C++结合使用,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);https://stackoverflow.com/questions/50610078
复制相似问题