mathutil and normal

if you have 3 or 4 points to form a tri or quad plane
located in 3D space and not at the origin!

is there some mathutil function that can help to get the normal to the plane from theses given points ?

would appreciate a simple example on how to do this

Thanks

You build from three points P1,P2,P3 (Vectors probably already!) two Vectors (in mathutils) , say v1 =P1-P2 and v2=P1-P3.
v1.cross(v2) delivers an orthogonal Vector (with respect to the plane spanned by v1 v2).

i tried to follow the wiki pagen on mathutil and it’s not working
may be other chnges to API

give me an example like how do you do a cross or dot product and use the normalize one
then i should be able to use it like in 2…49

first how do you import it ?

import mathutils
or you need to
from mathutils import * ?

let say with input vectors

p0=(1.0 ,1.0,1.0)
p1=(2,0,2.4,2.1)
p2=(5.0,3.0,4.0)

i tried this one and seems to work but not like in wiki !

v1=1.0, 2.0, 3.0
vec = mathutils.Vector(v1)

print (‘v1=’,v1 ,’ vec =’,vec)

so how do you enter the vec as tuple or as list ?
cause v1=1.0, 2.0, 3.0 is not a tuple or a list !

for angles this is seems to be workig fine

radians(90),

ang=90
print ()
print (’ ang =’,ang,’ deg radian =’,radians(ang),’ Rad’)

rad1=1.5
print (’ ang =’,rad1,’ radian =’,degrees(rad1),’ Deg’)
print ()

but then what and how ?

1 - cross product ?

2 - Dot product ?

3 - normalize?

Thanks and happy 2.5


from mathutils import Vector
from math import cos,pi

# input (note the double brackets)
p = [Vector((1.0 ,1.0,1.0)),Vector((2.0, 2.4, 2.1)),Vector((5.0, 3.0, 4.0))]

if len(p) == 3: # tri is always planar
    normal = (p[2]-p[1]).cross(p[0]-p[1]).normalize()
elif len(p) == 4:
    normal1 = (p[2]-p[1]).cross(p[0]-p[1]).normalize()
    normal2 = (p[3]-p[2]).cross(p[1]-p[2]).normalize()
    tolleranceAngle = 3 #degrees
    tollerance = cos(3/180*pi)
    angle = normal1.dot(normal2)
    if angle <= tollerance: # quad is (somewhat) planar
        normal = normal1
    else: # quad is not planar, take average
        normal = 0.5*(normal1+normal2)

print(normal) # prints the normal with length 1

hope that helps.
if not, i suggest u take a look at lineair algebra or vector algebra, because this is basic stuff in such topics. if u google this there are a lot of pages with excellent texts about it.

i tried this form and not working

v0=(1.0, 2.0, 3.0)
vec0 = mathutils.Vector(v0)

i got it as a tuple but still refusing to take it in the vector !

anyn idea why it’s refusing it ?

i’ll test the example given i think i get the general idea on how to use this now
this should ahve been incluede as ec ample in thw wiki page !

do you know if then other functions are available like

Get the vector from one point to anothers

def PtoPVector(v1,v2): return Mathutils.Vector(v1[0]-v2[0],v1[1]-v2[1],v1[2]-v2[2])

Get the distance between two locations

def PtoPDist(v1, v2): return PtoPVector(v1,v2).length

Thanks

There ist a second way. I have tried this in a Console-Window:

>>> from mathutils import Vector
>>> import geometry
>>> v1 = Vector((1,2,3))
>>> v2 = Vector((0,2,3))
>>> v3 = Vector((1,2,0))
>>> v4 = Vector((1,1,1))
>>> n1 = geometry.TriangleNormal(v1,v2,v3)
>>> print(n1)
Vector((0.0, -1.0, 0.0))

>>> n2 = geometry.QuadNormal(v1,v2,v3,v4)
>>> print(n2)
Vector((-0.7071067690849304, -0.7071067690849304, 0.0))

what i sthis geometry module ?

any good doc on this ?
1 would like to see all the functions available for this

intersting to get more functions!

another thing is that the angles are measure CW here
so if you take an angle in the first quarant it won’t give a positive but negative
i’m right here ?

i found an old page on this module
tested this line
polyline1= [Vector((-2.0, 1.0, 1.0)), Vector((-1.0, 2.0, 1.0)), Vector((1.0, 2.0, 1.0)), Vector((1.0, -1.0, 1.0)), Vector((-1.0, -1.0, 1.0))]
with tuple or not for vector but did notwokr
any idea on how to make it work ?

Thanks

anybody ehard something about this module

http://cgkit.sourceforge.net/doc2/spheregeom.html

don’t know if this can be used in blender ?

Thanks

The geometry module ist a builtin module. The builtin modules are listet in the console window.

Builtin Modules: bpy, bpy.data, bpy.ops, bpy.props, bpy.types, bpy.context, bgl, blf, mathutils, geometry

WARNING!!! Blender 2.5 API is subject to change, see API reference for more info.

>>> import geometry
>>> help(geometry)
There are some more informations in the documentation of blender 2.49

i was refering more to the 2.5 doc for this geometry module!

and what about the other commands for the mathutil ?

Thanks