How to use the vpython._vector_import_helper.vec 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 / shapespaths.py View on Github external
    def star(self, pos=vec(0,0,0), radius=3, n=5, iradius=None, rotate=0.0, thickness=None,
                      roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0, up=vec(0,1,0)):
            if thickness is not None:
                raise AttributeError("Thickness is not allowed in a star path")
            c = shapes.star(n=n, radius=radius, iradius=iradius, rotate=rotate,
                      roundness=roundness, invert=invert, scale=scale, xscale=xscale, yscale=yscale)
            return convert(pos=pos, up=up, points=c)
github vpython / vpython-jupyter / vpython / shapespaths.py View on Github external
    def rectangle(self, pos=vec(0,0,0), width=6, height=None, rotate=0.0, thickness=None,
                      roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0, up=vec(0,1,0)):
            if height == None: height = width
            if thickness is not None:
                raise AttributeError("Thickness is not allowed in a rectangular path")
            c = shapes.rectangle(width=width, height=height, rotate=rotate, thickness=0,
                      roundness=roundness, invert=invert, scale=scale, xscale=xscale, yscale=yscale)
            return convert(pos=pos, up=up, points=c)
github vpython / vpython-jupyter / vpython / shapespaths.py View on Github external
def pointlist(self, pos=[], rotate=0.0, thickness=None,
                      roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0, up=vec(0,1,0)):
            if thickness is not None:
                raise AttributeError("Thickness is not allowed in a pointlist path")
            # pos may be either a list of points or a Polygon object
            try:
                points = pos.contour(0)
                if len(pos) > 1:
                    raise AttributeError("pointlist can deal with only a single contour.")
            except:
                points = pos[:]
            closed = (points[-1] == points[0])
            if not closed:
                points.append(points[0])
            c = shapes.pointlist(pos=points, rotate=rotate, roundness=roundness, invert=invert,
                             scale=scale, xscale=xscale, yscale=yscale, path=True)
            return convert(pos=(0,0,0), up=up, points=c, closed=closed)
github vpython / vpython-jupyter / vpython / shapespaths.py View on Github external
def pentagon(self, pos=vec(0,0,0), np=5, length=6, rotate=0.0, thickness=None,
                      roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0, up=vec(0,1,0)):
            if thickness is not None:
                raise AttributeError("Thickness is not allowed in a pentagonal path")
            c = shapes.ngon(np=np, length=length, rotate=rotate+pi/10, thickness=0,
                      roundness=roundness, invert=invert, scale=scale, xscale=xscale, yscale=yscale)
            return convert(pos=pos, up=up, points=c)
github vpython / vpython-jupyter / vpython / shapespaths.py View on Github external
    def line(self, start=vec(0,0,0), end=vec(0,0,-1), np=2):
            if np < 2:
                raise AttributeError("The minimum value of np is 2 (one segment)")
            start = vector(start)
            end = vector(end)
            vline = (end-start)/(np-1)
            pos = []
            for i in range(np):
                pos.append(start + i*vline)
            return pos
github vpython / vpython-jupyter / vpython / shapespaths.py View on Github external
def circle(self, pos=vec(0,0,0), radius=3, np=32, thickness=None,
                      scale=1.0, xscale=1.0, yscale=1.0, up=vec(0,1,0)):
            if thickness is not None:
                raise AttributeError("Thickness is not allowed in a circular path")
            c = shapes.circle(radius=radius, np=np, scale=scale, xscale=xscale, yscale=yscale)
            return convert(pos=pos, up=up, points=c)
github vpython / vpython-jupyter / vpython / shapespaths.py View on Github external
def roundc(cps, roundness=0.1, invert=False, nseg=16):
    cp = []
    for i in range(len(cps)): cp.append(vec(cps[i][0], cps[i][1], 0)) # convert [x,y] => vec(x,y,0), so can use vector functions

    # If points are ordered counterclockwise, vord will be > 0
    vord = 0
    cp.pop() # remove the final point, which is equal to the initial point
    lcp = len(cp)
    for i in range(lcp):
        i1 = (i + 1) % lcp
        i2 = (i + 2) % lcp
        v1 = cp[i1] - cp[i]
        v2 = cp[i2] - cp[i1]
        dv = v1.cross(v2).z
        vord += dv

    if vord < 0: cp.reverse() # force points to be in counterclockwise order

    # Determine shortest side
github vpython / vpython-jupyter / vpython / shapespaths.py View on Github external
    def hexagon(self, pos=vec(0,0,0), np=6, length=6, rotate=0.0, thickness=None,
                      roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0, up=vec(0,1,0)):
            if thickness is not None:
                raise AttributeError("Thickness is not allowed in a hexagonal path")
            c = shapes.ngon(np=np, length=length, rotate=rotate, thickness=0,
                      roundness=roundness, invert=invert, scale=scale, xscale=xscale, yscale=yscale)
            return convert(pos=pos, up=up, points=c)
github vpython / vpython-jupyter / vpython / shapespaths.py View on Github external
    def ellipse(self, pos=vec(0,0,0), width=6, height=None, np=32, thickness=None,
                      scale=1.0, xscale=1.0, yscale=1.0, up=vec(0,1,0)):
            if thickness is not None:
                raise AttributeError("Thickness is not allowed in an elliptical path")
            c = shapes.ellipse(width=width, height=height, np=np, scale=scale, xscale=xscale, yscale=yscale)
            return convert(pos=pos, up=up, points=c)