# Face normal + Object rotation..?

**URL:** <https://blenderartists.org/t/face-normal-object-rotation/559600>\
**Category:** Python Support\
**Created:** [December 15, 2012, 5:13pm UTC](https://blenderartists.org/t/face-normal-object-rotation/559600 "2012-12-15T17:13:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ejnaren](https://blenderartists.org/user_avatar/blenderartists.org/ejnaren/32/645982_2.png) [@ejnaren](https://blenderartists.org/u/ejnaren)\
**Post date:** [December 15, 2012, 5:13pm UTC](https://blenderartists.org/t/face-normal-object-rotation/559600/1 "2012-12-15T17:13:40Z")

</div>

Hi all.  
I am newly into python in blender and I am working on a rewrite of a section script.  
It is goinf well and I can now get a section from a mesh, but I have a small problem…

I get a the normal of a polygon, but the normal is relative to the local space of the face… I need the normal in world space… So:  
1: I get the local normal and rotate it by the objects rotation. Problem: how do I rotate a normal?  
or…  
2: I get the normal relative to world space diractly. Can that be done?

Thanks. Hope to get the script done soon so I can share it…

---

<div class="post-metadata">

**Author:** ![ideasman42](https://blenderartists.org/user_avatar/blenderartists.org/ideasman42/32/900508_2.png) [@ideasman42](https://blenderartists.org/u/ideasman42)\
**Post date:** [December 15, 2012, 8:15pm UTC](https://blenderartists.org/t/face-normal-object-rotation/559600/2 "2012-12-15T20:15:18Z")

</div>

- removed incorrect suggestion \*

Sorry about that, normalized matrix are used for quaternion multiplication but not for normals.  
I didn’t use this stuff in a while and got it confused.

---

<div class="post-metadata">

**Author:** ![TrumanBlending](https://blenderartists.org/letter_avatar_proxy/v4/letter/t/ea5d25/32.png) [@TrumanBlending](https://blenderartists.org/u/TrumanBlending)\
**Post date:** [December 16, 2012, 3:28am UTC](https://blenderartists.org/t/face-normal-object-rotation/559600/3 "2012-12-16T03:28:22Z")

</div>

Hi ejnaren,

ideasman’s code just needs a slight tweak if your object is non-uniformly scaled (as that can change normal direction also) if that’s the case for you, you can use:

```auto
matrix = obj.matrix_world
matrix_new = matrix.to_3x3().inverted().transposed()
no_world = matrix_new * no
no_world.normalize()

```

The last line assumes that you want to maintain unit normal length (i.e. length of 1)

Hope that helps.

Cheers,  
Truman

---

<div class="post-metadata">

**Author:** ![ejnaren](https://blenderartists.org/user_avatar/blenderartists.org/ejnaren/32/645982_2.png) [@ejnaren](https://blenderartists.org/u/ejnaren)\
**Post date:** [December 16, 2012, 4:07am UTC](https://blenderartists.org/t/face-normal-object-rotation/559600/4 "2012-12-16T04:07:26Z")

</div>

Thanks ideasman and trumanblending!  
You just cant buy support like this.

---

<div class="post-metadata">

**Author:** ![ejnaren](https://blenderartists.org/user_avatar/blenderartists.org/ejnaren/32/645982_2.png) [@ejnaren](https://blenderartists.org/u/ejnaren)\
**Post date:** [December 16, 2012, 1:23pm UTC](https://blenderartists.org/t/face-normal-object-rotation/559600/5 "2012-12-16T13:23:05Z")

</div>

As said I am very new to blender scripting and while this helped me it is acually unclear to me why.  
I am porting a 2.49 scropt so I need not know to much about scripting to get results.  
In the 2.49 script one applies a matrix to a vector by just multiplying it, but in the 2.5 I need to use matrix.transposed() ??  
How come. Has the matrices in 2.5+ been flipped?

Anyway Thanks again. When I post the script/addon/tool maybe someone would like to look it over. There might be much easier ways to do this now or I might have unseen bugs crawling around the code. Even though I can know cut things by a plane in blender again 🙂

---

<div class="post-metadata">

**Author:** ![ejnaren](https://blenderartists.org/user_avatar/blenderartists.org/ejnaren/32/645982_2.png) [@ejnaren](https://blenderartists.org/u/ejnaren)\
**Post date:** [December 16, 2012, 4:47pm UTC](https://blenderartists.org/t/face-normal-object-rotation/559600/6 "2012-12-16T16:47:30Z")

</div>

Ok, so this is a first for me, but I would like to share what I have done so far, but I am not sure how to proceed about this.  
The script is still not ported 100% but it works and can cut an object, creating a section. The FILL option in hardcoded TRUE in the code because I havent yet figured out how to interact with the user through python.  
Also I am not really into matrix calc so I was kind of fumbling in blind, but with the above help got it to work.  
If anyone would like to look at it go for it as I have some other things I need to do before continuing with this 🙂

Link to newly ported script (2.65): [CrossSection.py](https://dl.dropbox.com/u/1161045/CrossSection.py)

Link to original script (2.49): [CrossSection](http://wiki.blender.org/index.php/Extensions:2.4/Py/Scripts/System/CrossSection)

Thanks.

Ejnaren

PS: If anyone have good ideas as to what is the best way to get into blender I would be happy to hear about it.

---

<div class="post-metadata">

**Author:** ![ideasman42](https://blenderartists.org/user_avatar/blenderartists.org/ideasman42/32/900508_2.png) [@ideasman42](https://blenderartists.org/u/ideasman42)\
**Post date:** [December 16, 2012, 9:10pm UTC](https://blenderartists.org/t/face-normal-object-rotation/559600/7 "2012-12-16T21:10:00Z")

</div>

Yes, @TrumanBlending changed this since 2.4x.  
[http://wiki.blender.org/index.php/User:TrumanBlending/Matrix\_Indexing](http://wiki.blender.org/index.php/User:TrumanBlending/Matrix_Indexing)

---

<div class="post-metadata">

**Author:** ![Afeitadora](https://blenderartists.org/user_avatar/blenderartists.org/afeitadora/32/22480_2.png) [@Afeitadora](https://blenderartists.org/u/Afeitadora)\
**Post date:** [December 17, 2012, 5:47am UTC](https://blenderartists.org/t/face-normal-object-rotation/559600/8 "2012-12-17T05:47:09Z")

</div>

Hey ejnaren, I like your port. It works fine for me except an error on line 252, changed that to

```auto
bpy.context.tool_settings.mesh_select_mode=(False,True,False)

```

For the next steps:  
You could make an Operator out of it, so its callable by a button in the GUI.  
There you could also have a Panel with a boolean Property for the fill option.  
In the internal Text Editor there some samples for UI Panels and Operators.

Feel free to ask if you get stuck.

---

<div class="post-metadata">

**Author:** ![ejnaren](https://blenderartists.org/user_avatar/blenderartists.org/ejnaren/32/645982_2.png) [@ejnaren](https://blenderartists.org/u/ejnaren)\
**Post date:** [January 5, 2013, 11:54am UTC](https://blenderartists.org/t/face-normal-object-rotation/559600/9 "2013-01-05T11:54:30Z")

</div>

> [@Afeitadora](#):
>
> Hey ejnaren, I like your port. It works fine for me except an error on line 252, changed that to
> 
> ```auto
> bpy.context.tool_settings.mesh_select_mode=(False,True,False)
> 
> ```
> 
> For the next steps:  
> You could make an Operator out of it, so its callable by a button in the GUI.  
> There you could also have a Panel with a boolean Property for the fill option.  
> In the internal Text Editor there some samples for UI Panels and Operators.
> 
> Feel free to ask if you get stuck.

Thanks Afeitadora!  
I am in the middle of launching my portfolio site and deliver my exams for this semester. After this I think I will finish the script as you mentioned.  
I have also thought of improving it with an option for multiple face sections so it can be ued for more intersections.  
For that I might call on help 😃

Roger over
