Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Vector3 type in Python?

Tags:

python

vector

I quickly checked numPy but it looks like it's using arrays as vectors? I am looking for a proper Vector3 type that I can instance and work on.

like image 325
Joan Venge Avatar asked Apr 24 '09 16:04

Joan Venge


People also ask

Do vectors exist in Python?

A vector in a simple term can be considered as a single-dimensional array. With respect to Python, a vector is a one-dimensional array of lists. It occupies the elements in a similar manner as that of a Python list.

How do you make a vector from 1 to 100 in Python?

import numpy as np a = np. zeros(0) for i in range(1,100): a = np. r_[a,np. repeat(i, 100)] print(a) [ 1.


2 Answers

ScientificPython has a Vector class. for example:

In [1]: from Scientific.Geometry import Vector
In [2]: v1 = Vector(1, 2, 3)
In [3]: v2 = Vector(0, 8, 2)               
In [4]: v1.cross(v2)
Out[4]: Vector(-20.000000,-2.000000,8.000000)
In [5]: v1.normal()
Out[5]: Vector(0.267261,0.534522,0.801784)
In [6]: v2.cross(v1)
Out[6]: Vector(20.000000,2.000000,-8.000000)
In [7]: v1*v2 # dot product
Out[7]: 22.0
like image 79
Autoplectic Avatar answered Oct 02 '22 07:10

Autoplectic


I don't believe there is anything standard (but I could be wrong, I don't keep up with python that closely).

It's very easy to implement though, and you may want to build on top of the numpy array as a container for it anyway, which gives you lots of good (and efficient) bits and pieces.

like image 43
simon Avatar answered Oct 02 '22 07:10

simon