n维向量数学库。
ndvector的Python项目详细描述
关于
ndvector是python3的另一个向量数学库。努比关注的地方 在包括厨房水槽在内的所有设备上,ndvector旨在提供 简单的、pythonic的、面向对象的api,用于n维向量数学。
许可证
apache许可证2.0(请参阅许可证)
要求
python=3.5
用法
用法试图达到您的预期。只需导入库,创建 点和向量对象,并对它们进行数学运算。
fromn_dimensionimportVectorv1=Vector(1.0,0.0)v2=Vector(-1.0,1.0)v3=v1+v2print(v3)# => Vector ‹0.0, 1.0›
API
给定:
- s a scalar (float)
- p, p# are instances of Point
- v, v# are instances of Vector
类Point
:
- constructor - create a Point from one or more float parameters, a tuple
of floats, or a list of floats
- properties:
- dimension - the dimension of the Point
- operators:
- 'p + v' addition of a Vector to a Point to get the Point at the tip of
the Vector if the tail of the vector is moved to the Point
- 'p1 - p2' subtraction of a Point from a Point to get the Vector between
the Points
- 'p1 == p2' equality (See Note 1)
- 'p1 != p2' not equality (See Note 1)
类Vector
:
- constructor - create a Vector from one or more float parameters, a tuple
of floats, or a list of floats
- properties:
- dimension - the dimension of the vector
- magnitude - the magnitude of the vector
- operators
- 'v1 + v2' vector addition
- 'v1 - v2' vector subtraction
- 'v1 * v2' scalar aka dot product (v1 * v2 => scalar)
- 'v * s' scale vector
- 'v1 @ v2' vector aka cross product (v1 * v2 => vector) (See Note 2)
- 'v1 == v2' equality (See Note 1)
- 'v1 != v2' not equality (See Note 1)
- methods
- angle() - find the angle in radians between the vector and another vector
- normalize() - find a unit vector with the same direction as the vector
注释
- 当涉及到浮点数时,测试相等性是很棘手的。nU维度 如果两个浮点数的绝对值 差额小于一定数额;目前0.000001似乎 干得好。在进行更多测试后,可能会改进此功能
- 仅对三维(3)向量实现
测试
使用tox
和pytest
进行测试。见
https://tox.readthedocs.io/en/latest/获取有关安装tox的信息。
通过克隆源存储库并将其更改为本地存储库来运行测试
工作目录,并调用tox
。
git clone https://github.com/tkegan/n_dimension.git
cd n_dimension
tox
待办事项
创建更好的API文档
通过将某些功能移到编译的代码中来研究加速的性能,但前提是纯python实现可以作为回退而保留
贡献
我欢迎针对github存储库的pull请求。如果扩展API,请包括测试。在测试到位并通过之前,我不会将更改合并到api。