How to use the payton.math.vector.distance 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 / payton / tools / mesh / geometry.py View on Github external
has_texcoords = len(original._texcoords) == len(original._vertices)
        new.clear_triangles()

        for indice in original._indices:
            v1 = original._vertices[indice[0]]
            v2 = original._vertices[indice[1]]
            v3 = original._vertices[indice[2]]

            a = v1
            a_i = indice[0]
            b = v2
            b_i = indice[1]
            c = v3
            c_i = indice[2]

            if distance(v2, v3) > distance(v1, v2):
                a = v2
                a_i = indice[1]
                b = v3
                b_i = indice[2]
                c = v1
                c_i = indice[0]

            if distance(v3, v1) > distance(v2, v3):
                a = v3
                a_i = indice[2]
                b = v1
                b_i = indice[0]
                c = v2
                c_i = indice[1]

            vc = mid_point(a, b)
github sinanislekdemir / payton / examples / basics / 33_better_lines.py View on Github external
def animate(self, period, total):
        for i, vertex in enumerate(self.line._vertices):
            if distance([0, 0, 0], vertex) > 30:
                self.vertex_velocities[i] = scale_vector(self.vertex_velocities[i], -1)
            vertex[0] += self.vertex_velocities[i][0]
            vertex[1] += self.vertex_velocities[i][1]
            vertex[2] += self.vertex_velocities[i][2]

        self.line.refresh()
github sinanislekdemir / payton / payton / scene / geometry / base.py View on Github external
def _calc_bounds(self) -> float:
        bmin: Optional[List[float]] = None
        bmax: Optional[List[float]] = None
        x = [v[0] for v in self._vertices]
        y = [v[1] for v in self._vertices]
        z = [v[2] for v in self._vertices]

        if len(x) == 0 or len(y) == 0 or len(z) == 0:
            bmin = [0.0, 0.0, 0.0]
            bmax = [0.0, 0.0, 0.0]
        else:
            bmin = [min(x), min(y), min(z)]
            bmax = [max(x), max(y), max(z)]

        self._bounding_radius = distance(bmax, bmin) / 2.0
        self._bounding_box = [bmin, bmax]

        return self._bounding_radius
github sinanislekdemir / payton / examples / basics / 28_ragdoll.py View on Github external
def walk(self, period, total):
        self.total_ang += self.state
        ang = self.state

        self.ragdoll.joints[R_HIP].rotate_around_x(math.radians(ang))
        self.ragdoll.joints[L_HIP].rotate_around_x(math.radians(-ang))
        self.ragdoll.joints[R_SHOULDER].rotate_around_x(math.radians(-ang))
        self.ragdoll.joints[L_SHOULDER].rotate_around_x(math.radians(ang))
        if self.total_ang > 40:
            self.state = -1
        if self.total_ang < -40:
            self.state = 1
        self.ragdoll.forward(0.025)
        if distance(self.target, self.ragdoll.position) < 0.5:
            self.target = [
                float(random.randint(-10, 10)),
                float(random.randint(-10, 10)),
                2,
            ]
            self.ragdoll.direct_to(self.target)
        if self.ragdoll.position[0] >= 10:
            self.ragdoll.position = [-10, 0, 2]
github sinanislekdemir / payton / payton / tools / mesh / geometry.py View on Github external
a = v1
            a_i = indice[0]
            b = v2
            b_i = indice[1]
            c = v3
            c_i = indice[2]

            if distance(v2, v3) > distance(v1, v2):
                a = v2
                a_i = indice[1]
                b = v3
                b_i = indice[2]
                c = v1
                c_i = indice[0]

            if distance(v3, v1) > distance(v2, v3):
                a = v3
                a_i = indice[2]
                b = v1
                b_i = indice[0]
                c = v2
                c_i = indice[1]

            vc = mid_point(a, b)
            n1 = original._normals[indice[0]]
            texcoords_1 = None
            texcoords_2 = None
            if has_texcoords:
                t1 = original._texcoords[a_i]
                t2 = original._texcoords[b_i]
                t3 = original._texcoords[c_i]
github sinanislekdemir / payton / examples / mid-level / rpg.py View on Github external
def move_to_target(period, total):
    if distance(scene.objects["dir"].position, target) > 0.1:
        scene.objects["dir"].forward(0.1)
github sinanislekdemir / payton / examples / mid-level / quake2.py View on Github external
def walk(self, period, total):
        if self.objects["warrior"].animation == "":
            self.objects["warrior"].animate("run", 0, 24)
        self.objects["warrior"].forward(0.04)
        if distance(self.target, self.objects["warrior"].position) < 0.5:
            self.target = [
                float(random.randint(-10, 10)),
                float(random.randint(-10, 10)),
                0,
            ]
            self.objects["warrior"].direct_to(self.target)
        if self.objects["warrior"].position[0] >= 10:
            self.objects["warrior"].position = [-10, 0, 0]