Dare I say, normalise isn’t giving me the results I expect…
I’ve set up a file with some meshes which each contain three points, the middle point is always on local (0,0,0).
Here’s the script which calculates the internal angle:
import bpy
import mathutils, math
print("
")
objs = bpy.context.selected_objects
o =objs[0]
v=o.data.vertices
v1=mathutils.Vector((v[0].co[0],v[0].co[1]))
v2=mathutils.Vector((v[2].co[0],v[2].co[1]))
v1.normalize()
print("v1n:",v1)
v2.normalize()
print("v2n:",v2)
v3 = v1.dot(v2)
a = math.acos(v3)
print("a:",a)
To recreate my issue, make a right angle with arms 1 unit in length, then using the origin for rotation rotate an arm 45 degrees. If you run the script it will print out “a: 0.7853979821219895”, which is 45 degrees.
Now if you duplicate this right angle object and then in edit mode select all and subdivide. Next delete the far points, so in effect you have two arms each of 0.5 units. If you now run the script, even though the angle is the same, I get “a: 1.3734007523747485”. :eek:
that is it
when you change the value in edit mode it is not reflected in the object
look at N transform panel the lengh edge angle ect are not the real values
so by doing a ctrl A it might bring it back and then you will get the real values i think!
but not certain if this can affect the mathutils values!
When a mesh has vertices added/deleted the vertex indices may change. So while the vertex indices for the ends of the two arms are initially 0 and 2, after editting they change. You need to make sure the vertices you are using are still the ends of the arms. Also, a few extra goodies!
You can resize a vector to get the x and y coords
v1=v[0].co.copy()
v1.resize_2d()
You can measure the angle directly using mathutils vectors without needing to normalise!