How to use the vpython.vector.vector function in vpython

To help you get started, we’ve selected a few vpython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vpython / vpython-jupyter / vpython / vector.py View on Github external
def __neg__(self):
        return vector(-self._x, -self._y, -self._z)
github vpython / vpython-jupyter / vpython / vector.py View on Github external
def __mul__(self, other):
        if isinstance(other, (float, int)):
            return vector(self._x * other, self._y * other, self._z * other)
        return NotImplemented
github vpython / vpython-jupyter / vpython / vector.py View on Github external
def __init__(self, *args):
        if len(args) == 3:
            self._x = float(args[0]) # make sure it's a float; could be numpy.float64
            self._y = float(args[1])
            self._z = float(args[2])
        elif len(args) == 1 and isinstance(args[0], vector): # make a copy of a vector
            other = args[0]
            self._x = other._x
            self._y = other._y
            self._z = other._z
        else:
            raise TypeError('A vector needs 3 components.')
        self.on_change = self.ignore
github vpython / vpython-jupyter / vpython / vector.py View on Github external
def __rmul__(self, other):
        if isinstance(other, (float, int)):
            return vector(self._x * other, self._y * other, self._z * other)
        return NotImplemented
github vpython / vpython-jupyter / vpython / vector.py View on Github external
def __add__(self, other):
        if type(other) is vector:
            return vector(self._x + other._x, self._y + other._y, self._z + other._z)
        return NotImplemented
github vpython / vpython-jupyter / vpython / vector.py View on Github external
def __ne__(self,other):
        if type(self) is vector and type(other) is vector:
            return not self.equals(other)
        return True
github vpython / vpython-jupyter / vpython / vector.py View on Github external
def rotate(self, angle=0., axis=None):
        if axis is None:
            u = vector(0,0,1)
        else:
            u = axis.hat
        c = cos(angle)
        s = sin(angle)
        t = 1.0 - c
        x = u._x
        y = u._y
        z = u._z
        m11 = t*x*x+c
        m12 = t*x*y-z*s
        m13 = t*x*z+y*s
        m21 = t*x*y+z*s
        m22 = t*y*y+c
        m23 = t*y*z-x*s
        m31 = t*x*z-y*s
        m32 = t*y*z+x*s
github vpython / vpython-jupyter / vpython / vector.py View on Github external
def rotate_in_place(self, angle=0., axis=None):
        if axis is None:
            u = vector(0,0,1)
        else:
            u = axis.hat
        c = cos(angle)
        s = sin(angle)
        t = 1.0 - c
        x = u._x
        y = u._y
        z = u._z
        m11 = t*x*x+c
        m12 = t*x*y-z*s
        m13 = t*x*z+y*s
        m21 = t*x*y+z*s
        m22 = t*y*y+c
        m23 = t*y*z-x*s
        m31 = t*x*z-y*s
        m32 = t*y*z+x*s
github vpython / vpython-jupyter / vpython / vector.py View on Github external
def __sub__(self, other):
        if type(other) is vector:
            return vector(self._x - other._x, self._y - other._y, self._z - other._z)
        return NotImplemented
github vpython / vpython-jupyter / vpython / vector.py View on Github external
def __truediv__(self, other): # used by Python 3, and by Python 2 in the presence of __future__ division
        if isinstance(other, (float, int)):
            return vector(self._x / other, self._y / other, self._z / other)
        return NotImplemented