I want to find angle of an cylinder so that it will always perpendicular to the position in another object faces. I got face(polygon in python) position by 'bpy.context.active_object.data.polygons['index_number'].center' and each face also have rotation saved as 'bpy.context.active_object.data.polygons['index_number'].normal' . For the cylinder I also have cylinder angle by 'rotation_euler'. In Attached photo the green one is fine. but the red one seems not perpendicular to the face. Anyone can help? Thanks.
According to batFINGER comment, I checked those posts and try some variation and found my expected solution. I used .normal.to_track_quat('Z','X') for each face to make it perpendicular and convert it .to_euler() for each face (or polygon in python). For example, if I want the cylinder to be perpendicular to face number 116 then code will like,
polygon = bpy.data.objects['Circle'].data.polygons
cylinder = bpy.data.objects['Cylinder']
cylinder.location = polygon.center
cylinder.rotation_euler = polygon.normal.to_track_quat('Z','X').to_euler()