# How to get the angle between three faces on a non regular non flat surface

I've got a non flat and non regular surface with three selected faces. Is there a way to get the smallest angle between these with python? • Is it related to camera space at all? Like, are the lines meant to be contained within the same plane? – someonewithpc Feb 26 '16 at 0:39
• No there is no relation. Just the smallest angle would be great. – Basti Feb 26 '16 at 11:14

Here's a slightly different approach. The solution below treats the three faces as a triangle. The script calculates all 3 triangle angles, then sums the two smaller angles to find the answer.

As shown in the image below, they are equal to the angle between the edges of the larger angle within the triangle. import bpy, bmesh
from mathutils import Vector
from math import degrees, acos

bm = bmesh.from_edit_mesh( bpy.context.object.data )
centers = [ f.calc_center_median() * bpy.context.object.matrix_world for f in bm.faces if f.select ]

if len( centers ) == 3:
# Face centers as triangle vertices
A, B, C = centers

# Triangle edges (sides)
AB = B - A
AC = C - A
BC = C - B

# Triangle angles
a =       degrees( acos( ( AB.dot( AC ) ) / ( AB.length * AC.length ) ) )
b = 180 - degrees( acos( ( AB.dot( BC ) ) / ( AB.length * BC.length ) ) )
c =       degrees( acos( ( BC.dot( AC ) ) / ( BC.length * AC.length ) ) )

# The smallest angle between the two triangle edge vectors equals
# To the sum of the two smallest angles within the triangle
angles = sorted( [ a, b, c ] )
print( angles )
print( "All: ", sum( angles ) )
print( "Two smaller: ", sum( angles[:2] ) )

else:
print( "Invalid number of selected faces" )


This is what I have so far. It doesn't seem to quite work, but I have to go and don't want to waste my efforts. There is one problem with it: to know which vector to use as the center, it calculates the distance to the object center, instead of the (intended) median selection point.

import bmesh
import bpy
import mathutils

bm = bmesh.new()
obj = bpy.context.object
bm.from_mesh(obj.data)
zero = mathutils.Vector((0, 0, 0))

vec = None
minSq = 0
vec_list = list()
for f in bm.faces:
if f.select:
center = f.calc_center_median()
distSq = (center - obj.location).dot(center - obj.location)

if vec == None:
vec = center
minSq = distSq

if distSq < minSq:
vec = center

for f in bm.faces:
if f.select:
if (f.calc_center_median() - vec) != zero:
vec_list.append(f.calc_center_median() - vec)

print(len(vec_list))
if len(vec_list) != 3:
print("Select only three faces")
else:
print(vec_list.angle(vec_list))

bm.free()
{"ft_lang_label":"__label__en","ft_lang_prob":0.7455891,"math_prob":0.9879467,"size":2597,"snap":"2020-10-2020-16","text_gpt3_token_len":702,"char_repetition_ratio":0.12032395,"word_repetition_ratio":0.02603037,"special_character_ratio":0.2991914,"punctuation_ratio":0.16763006,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9996964,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,2,null,2,null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-02-21T20:21:42Z\",\"WARC-Record-ID\":\"<urn:uuid:c2ed283a-eb1f-4e3f-a856-d8ac23ae7e64>\",\"Content-Length\":\"149992\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:03dea8ca-8f94-47f3-aeeb-312e76f54d68>\",\"WARC-Concurrent-To\":\"<urn:uuid:608064b8-4b1d-4e70-9c47-cce7fb28cb63>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://blender.stackexchange.com/questions/47711/how-to-get-the-angle-between-three-faces-on-a-non-regular-non-flat-surface\",\"WARC-Payload-Digest\":\"sha1:VVSEOPR6ITMRHFSQFCMZB5WJJE7ZVZCD\",\"WARC-Block-Digest\":\"sha1:BW7UAJDFEYXOOOMQDTX2VYGVSDO4VS3B\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-10/CC-MAIN-2020-10_segments_1581875145534.11_warc_CC-MAIN-20200221172509-20200221202509-00085.warc.gz\"}"}