Python 的 3d 数学库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1556813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 22:34:49  来源:igfitidea点击:

3d Math Library For Python

pythonmath3d

提问by spearfire

i'm looking for a 3d math library in python or with python bindings.

我正在寻找 python 或 python 绑定的 3d 数学库。

it needs to handle rotation, translation, perspective projection, everything basically.

它需要处理旋转,平移,透视投影,基本上所有的事情。

what im NOT looking for is a library aimed at drawing on the screen, googling for hours only led to 3d libraries bent on rendering something to the screen. i dont want any visualization whatsoever, all i need is to be able feed a library x,y,z coordinates and recieve the x,y screen coordinates.

我不是在寻找一个旨在在屏幕上绘图的库,谷歌搜索几个小时只会导致 3d 库倾向于将某些内容渲染到屏幕上。我不想要任何可视化,我所需要的只是能够提供库 x、y、z 坐标并接收 x、y 屏幕坐标。

i dont mind if its a visualization library, as long as it can be used without rendering anything to the screen.

我不介意它是否是一个可视化库,只要它可以在不向屏幕呈现任何内容的情况下使用。

is there anything like this for python?

python有这样的东西吗?

Edit: please dont recommend scipy/numpy as they arent aimed at 3d math but at math in general, they look like great tools if i wanted to build the library myself, which i dont. thanks.

编辑:请不要推荐 scipy/numpy,因为它们不是针对 3d 数学而是针对数学的,如果我想自己构建库,它们看起来像是很棒的工具,我不这样做。谢谢。

采纳答案by evan

Try gameobjects-- it's a math library that includes Python classes for matrices and vectors, along with methods for transformations. I think it will provide most (if not all) of what you need, plus it's pure Python so you can modify it if you need to.

试试游戏对象——它是一个数学库,包括用于矩阵和向量的 Python 类,以及用于转换的方法。我认为它将提供您需要的大部分(如果不是全部),而且它是纯 Python,因此您可以根据需要对其进行修改。

回答by Jacob

OpenCV - Python Interfacecan handle all the operations you've mentioned.

OpenCV - Python 接口可以处理您提到的所有操作。

I hear SciPy's excellent for this as well, but I've only used OpenCV.

我听说SciPy在这方面也很出色,但我只使用过 OpenCV。

回答by evan

transformations.py

转换.py

A library for calculating 4x4 matrices for translating, rotating, reflecting, scaling, shearing, projecting, orthogonalizing, and superimposing arrays of 3D homogeneous coordinates as well as for converting between rotation matrices, Euler angles, and quaternions. Also includes an Arcball control object and functions to decompose transformation matrices.

用于计算 4x4 矩阵的库,用于平移、旋转、反射、缩放、剪切、投影、正交化和叠加 3D 齐次坐标数组,以及用于在旋转矩阵、欧拉角和四元数之间进行转换。还包括一个 Arcball 控制对象和用于分解变换矩阵的函数。

Authors: Christoph Gohlke http://www.lfd.uci.edu/~gohlke/Laboratory for Fluorescence Dynamics, University of California, Irvine

作者:Christoph Gohlke http://www.lfd.uci.edu/~gohlke/加州大学欧文分校荧光动力学实验室

回答by Olivier RD

python-math3d is another good 3D mathematic library which is object oriented https://github.com/mortlind/pymath3d

python-math3d 是另一个很好的面向对象的 3D 数学库 https://github.com/mortlind/pymath3d

import math3d as m3d

将 math3d 导入为 m3d

v = m3d.Vector(1,2,3) # A vector object

v = m3d.Vector(1,2,3) # 一个向量对象

o = m3d.Orientation.new_euler((1,0,0), "ZYX") # An Orientation object from one type of euler angles

o = m3d.Orientation.new_euler((1,0,0), "ZYX") # 一种欧拉角的方向对象

t = m3d.Transform(o, v) # A Transform object created using the vector and orientation

t = m3d.Transform(o, v) # 使用向量和方向创建的 Transform 对象

t2 = m3d.Transform()# Another Transform object (Identity)

t2 = m3d.Transform()#另一个Transform对象(身份)

t2.orient.rotate_x(3) # rotate the transformation around x

t2.orient.rotate_x(3) # 围绕x旋转变换

res = t * t2 #Matrix multiplication

res = t * t2 #矩阵乘法

回答by Madhusudan.C.S

I would suggest MayaVi. Please take a look at the given link. It does almost everything you mentioned.

我会建议MayaVi。请看一下给定的链接。它几乎可以完成你提到的所有事情。

回答by Adam Griffiths

I'm working on one now. https://github.com/adamlwgriffiths/Pyrr

我现在正在做一个。 https://github.com/adamlwgriffiths/Pyrr

It uses numpy for speed. The aim is to provide a pure python 3D maths lib.

它使用 numpy 来提高速度。目的是提供一个纯 python 3D 数学库。

I'm avoiding external libs because I'm sick of having to follow complex software installs. Python should be easy.

我避免使用外部库,因为我厌倦了必须遵循复杂的软件安装。Python应该很容易。

回答by Paul Du Bois

http://cgkit.sourceforge.net/doc/index.html

http://cgkit.sourceforge.net/doc/index.html

The implementation isn't always the best, but it includes quaternions as well as the standard matrix and vector types. I've used it for tools on a couple commercial game projects.

实现并不总是最好的,但它包括四元数以及标准矩阵和向量类型。我已经将它用于几个商业游戏项目的工具。

回答by Eric O Lebigot

What about PyGame? I never used it, but it may contain what you're looking for.

什么pygame的?我从未使用过它,但它可能包含您要查找的内容。