I am trying to use the technique described here Python: Calculate angle between vertices to determine the angles between a list of vertices that is sorted left to right on the x axis

        mylen2 = len(vertices)
        if(mylen2 > 1): 
            a1 = vertices[mylen2-1].co.angle(vertices[mylen2-2].co)
            if a1 > pi * 0.5:
                a1 = pi - a1
            print("{:.2f} degrees".format(degrees(a1)))

My output looks like this:

enter image description here

but my vertices are like this:

enter image description here

I can't imagine these angles are all less than 10 degrees especially since many appear to be on a 45 degree angle.

How can I correctly find the angles for a list of vertices in degrees?


1 Answer 1


Vert co as a vector is from origin point.

enter image description here

Diagram where the red ico is the origin of a mesh and the other icos are the vertices.

Question code is calculating the angle designated as alpha above between the vectors defined by the two vertex coordinates.

It appears you are after (beta) the angle between the vector made from two verts

vec = verts[i].co - verts[i - 1].co

and the x axis Vector((1, 0, 0)).angle(vec) or if the points do not all lie on same XZ plane, the projection of vec onto the XY plane containing point verts[i - 1].co.

Example from python console, consider vec = Vector((1, 1, 1)) ie this is the result when subtracting i-1th vert from ith. Meaning if you travel (1, 1, 1) from vert[i-1] you will be at the location of vert[i]

>>> vec = Vector((1, 1, 1))
>>> x_axis = Vector((1, 0, 0))

Angle between 3d vectors

>>> degrees(x_axis.angle(vec))

To project as 2d vectors onto Y=constant plane, can get the signed angle between the 2d vectors ignoring y.

>>> degrees(x_axis.xz.angle_signed(vec.xz))
  • $\begingroup$ the vertices are all on y=0 $\endgroup$ Sep 15, 2020 at 5:37
  • $\begingroup$ Okay. I get that co gets the angle from 0,0 but how do I get the angle between two of the vertices? $\endgroup$ Sep 15, 2020 at 5:41
  • $\begingroup$ There is no angle between two points. without some other reference vector. Have explained what you are calculating in question (alpha) and how to get what I assume you are after the angle beta. Can't go north west from point A to point B without having some reference of what north and west is. Just looked at link posted in question, also points out that a reference vector is required. $\endgroup$
    – batFINGER
    Sep 15, 2020 at 5:45
  • $\begingroup$ or to put this another way, have used grease pencil to demonstrate the angles alpha and beta. Edit your question with diagram of expected "angle between two vertices". $\endgroup$
    – batFINGER
    Sep 15, 2020 at 6:17
  • $\begingroup$ yes beta. The angle between the two points. $\endgroup$ Sep 15, 2020 at 19:36

You must log in to answer this question.

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