vector math:python的矢量数学实用程序
vectormath的Python项目详细描述
向量路径
python的向量数学实用程序构建在NumPy
为什么
vectormath
包提供了一个快速、简单的矢量数学库
利用numpy的实用程序。这允许显式
要创建的几何结构(例如,Vector3
和Plane
)
不需要重新定义底层数组数学。
范围
vectormath
包包括Vector3
/Vector2
和
Vector3Array
/Vector2Array
。
目标
- 速度:所有低级操作都依赖于numpy数组。这些都是密密麻麻的, 类型化的,并在c中部分实现的。 利用此速度,在 一次,而不是一个循环。
- 简单:高级操作是明确和直接的。 程序员、数学家和地质学家应该可以使用这个库。
连接
- properties使用
vectormath
作为向量属性的基础框架。
安装
要安装存储库,请确保 pip installed然后运行:
pip install vectormath
对于开发版本:
git clone https://github.com/seequent/vectormath.git cd vectormath pip install -e .
示例
此示例简要演示了
Vector3
和Vector3Array
importnumpyasnpimportvectormathasvmath# Single Vectorsv=vmath.Vector3(5,0,0)v.normalize()print(v)# >> [1, 0, 0]print(v.x)# >> 1.0# VectorArrays are much faster than a for loop over Vectorsv_array=vmath.Vector3Array([[4,0,0],[0,2,0],[0,0,3]])print(v_array.x)# >> [4, 0, 0]print(v_array.length)# >> [4, 2, 3]print(v_array.normalize())# >> [[1, 0, 0], [0, 1, 0], [0, 0, 1]]# Vectors can be accessed individually or in slicesprint(type(v_array[1:]))# >> vectormath.Vector3Arrayprint(type(v_array[2]))# >> vectormath.Vector3# All these classes are just numpy arraysprint(isinstance(v,np.ndarray))# >> Trueprint(type(v_array[1:,1:]))# >> numpy.ndarray
当前版本:v0.2.2