1
$\begingroup$

I need to get a distance from the vertex to the vertex along the normal of the polygon. Look, I've got a polygon that I want to move to its normal to any too. In this case, I move the polygon with index 36 to the vertex with index 31 to the normals. I just include snapping to the vertex with the closest parameter. I get the distance of 0.3568. How can I reach the distance of 0.3568 between the 30 and 31 vertex using Python?

enter image description here enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

Use a dot product between the normal and the distance vector for the distance along normal.

import bpy
import numpy as np
from mathutils import Vector

# Use active object and active face in its mesh
ob = bpy.context.object
mesh = ob.data
normal = mesh.polygons[mesh.polygons.active].normal

# v1 is the origin point and v2 is moved to v1 along the active face normal
v1 = mesh.vertices[30]
v2 = mesh.vertices[31]

dvec = v1.co-v2.co
dnormal = np.dot(dvec, normal)

v2.co += Vector(dnormal*normal)
$\endgroup$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .