How to use the payton.math.vector.normalize_vector function in Payton

To help you get started, we’ve selected a few Payton 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 sinanislekdemir / payton / examples / basics / 33_better_lines.py View on Github external
def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.line = Line()
        self.vertex_velocities = []
        self.line.material.color = RED
        self.grid.visible = False

        for i in range(20):
            x = random.randint(-1000, 1000) / 100
            y = random.randint(-1000, 1000) / 100
            z = random.randint(-1000, 1000) / 100
            self.line.append(vertices=[[x, y, z]])
            v = normalize_vector([x, y, z])
            if random.randint(0, 1) == 1:
                v = scale_vector(v, -1)
            self.vertex_velocities.append(v)

        self.add_object("line", self.line)
        self.create_clock("clock", 0.01, self.animate)
        self.background.top_color = BLACK
        self.background.bottom_color = BLACK
        self.add_object(
            "info", info_box(left=10, top=10, width=220, height=100, label="Hit SPACE\nto start animation",),
        )
github sinanislekdemir / payton / payton / scene / geometry / base.py View on Github external
def direct_to(self, v: List[float]):
        diff = sub_vector(v, self.position)
        diff = normalize_vector(diff)
        self.direction = diff
github sinanislekdemir / payton / payton / math / matrix.py View on Github external
def create_rotation_matrix_raw(axis: GArray, angle: float) -> np.ndarray:
    sin = math.sin(angle)
    cos = math.cos(angle)
    m_cos = 1 - cos
    axis = normalize_vector(axis)
    result = deepcopy(IDENTITY_MATRIX)

    result[0][0] = (m_cos * axis[0] * axis[0]) + cos
    result[0][1] = (m_cos * axis[0] * axis[1]) - (axis[2] * sin)
    result[0][2] = (m_cos * axis[2] * axis[0]) + (axis[1] * sin)
    result[0][3] = 0

    result[1][0] = (m_cos * axis[0] * axis[1]) + (axis[2] * sin)
    result[1][1] = (m_cos * axis[1] * axis[1]) + cos
    result[1][2] = (m_cos * axis[1] * axis[2]) - (axis[0] * sin)
    result[1][3] = 0

    result[2][0] = (m_cos * axis[2] * axis[0]) - (axis[1] * sin)
    result[2][1] = (m_cos * axis[1] * axis[2]) + (axis[0] * sin)
    result[2][2] = (m_cos * axis[2] * axis[2]) + cos
    result[2][3] = 0
github sinanislekdemir / payton / payton / scene / geometry / base.py View on Github external
def direction(self, v: List[float]):
        if len(v) < 3:
            raise Exception("Direction needs 3 components (x,y,z)")
        self.matrix[1][0] = v[0]
        self.matrix[1][1] = v[1]
        self.matrix[1][2] = v[2]
        left = cross_product(self.matrix[1], self.matrix[2])
        left += [0]
        self.matrix[0] = normalize_vector(left)
        up = cross_product(self.matrix[0], self.matrix[1])
        up += [0]
        self.matrix[2] = normalize_vector(up)
github sinanislekdemir / payton / payton / scene / geometry / base.py View on Github external
def direction(self, v: List[float]):
        if len(v) < 3:
            raise Exception("Direction needs 3 components (x,y,z)")
        self.matrix[1][0] = v[0]
        self.matrix[1][1] = v[1]
        self.matrix[1][2] = v[2]
        left = cross_product(self.matrix[1], self.matrix[2])
        left += [0]
        self.matrix[0] = normalize_vector(left)
        up = cross_product(self.matrix[0], self.matrix[1])
        up += [0]
        self.matrix[2] = normalize_vector(up)