跳转到主要内容

vectormath:Python的矢量数学工具

项目描述

vectormath

Latest PyPI version MIT license Travis CI build status Code test coverage

基于NumPy构建的Python矢量数学工具

为什么

vectormath包通过利用NumPy提供了一套快速、简单的矢量数学工具库。这使得可以创建显式的几何构造(例如,Vector3Plane),而不必重新定义底层数组数学。

范围

vectormath包包括Vector3/Vector2Vector3Array/Vector2Array

目标

  • 速度:所有低级操作都依赖于NumPy数组。这些数组密集、有类型,部分在C语言中实现。特别是VectorArray类通过一次对所有向量执行向量运算,而不是循环,从而利用了这种速度。

  • 简单性:高级操作明确且直接。这个库应该可以被程序员、数学家和地质学家使用。

替代方案

  • 可以使用NumPy进行任何数组操作

  • PyPI上有许多小型库(例如vectors)实现了向量数学操作,但它们只针对单个向量构建。

连接

  • propertiesvectormath用作底层框架,以实现向量属性。

安装

要安装存储库,请确保您已安装pip并运行

pip install vectormath

对于开发版本

git clone https://github.com/seequent/vectormath.git
cd vectormath
pip install -e .

示例

此示例简要演示了Vector3Vector3Array的一些显著特性。

import numpy as np
import vectormath as vmath

# Single Vectors
v = 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 Vectors
v_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 slices
print(type(v_array[1:]))          # >> vectormath.Vector3Array
print(type(v_array[2]))           # >> vectormath.Vector3

# All these classes are just numpy arrays
print(isinstance(v, np.ndarray))  # >> True
print(type(v_array[1:, 1:]))      # >> numpy.ndarray

当前版本:v0.2.2

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

vectormath-0.2.2.tar.gz (9.2 kB 查看哈希值)

上传时间

由以下支持

AWSAWS 云计算和安全赞助商 DatadogDatadog 监控 FastlyFastly CDN GoogleGoogle 下载分析 MicrosoftMicrosoft PSF赞助商 PingdomPingdom 监控 SentrySentry 错误日志 StatusPageStatusPage 状态页面