0
$\begingroup$

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.

figure 1

$\endgroup$
8
  • $\begingroup$ I did not find related questions, if any then request to give link. $\endgroup$
    – dip deb
    Aug 16 '21 at 8:40
  • $\begingroup$ To little information. How do you get polygon number? How do you run the script? Why don't you use snap instruments? $\endgroup$
    – Crantisz
    Aug 16 '21 at 8:44
  • $\begingroup$ That I can handle. Just run a for loop and find out new polygons with area range. For a particular polygon or face its position and normal is fixed. So using that information I want to set cylinder with perpendicular to that specific face. $\endgroup$
    – dip deb
    Aug 16 '21 at 9:10
  • $\begingroup$ Hello ! It may be your "get_perpendicular_angle" (or however you named it) function has a flaw. Could you post a snippet of the algorithm ? Also, you almost certainly will hit a roadblock once you start rotating or moving your objects in world space. Make sure you familiarize yourself with object.matrix_world which is used to transform from local to global space and vice versa $\endgroup$
    – Gorgious
    Aug 16 '21 at 9:13
  • 1
    $\begingroup$ Do you change the position also? Just to make sure that correct face has been picked? $\endgroup$
    – Crantisz
    Aug 16 '21 at 9:13
1
$\begingroup$

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[116].center

cylinder.rotation_euler = polygon[116].normal.to_track_quat('Z','X').to_euler()

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.