a function to test that a list of vertecies is in same plane than vertecies a,b and c

Is there a function that take 2 list of vertecies (liste_to_be_tested and list_already_in_a_plane) and return the list of vertecies from liste_to_be_tested that are in the same plane as the one in list_already_in_a_plane ?

yes, it’s called cosine :slight_smile:

dot the vector of the plane defined by ABC normal with the vector from any point in the plane (conveniently A,B or C) to the points P you are testing.

If you mean a built in function, you may want to check out geometryutils. can’t remember what’s in there

edit: Re-reading your qeustion, I think you mean something more built in.

>>> geometry_utils.geometry.

I’m thinking that “distance point to plane” will be your best bet. If that distance is 0…it’s co planar. You can easily write you own function to test a whole list of points and do what you described.

Thanks Patmo,
I’ll try it as soon as i’m back on my computer. I wanted something build-in cause i don’t want to programme something that already exist and i think an API call is better than python because it calls a compiled C function, wich is so much efficienter. But i may be wrong.
For the distance, i was asking myself what error can be seen as a “float” error. I mean, even the cube after some rotation surely has not the 4 vertecies of his faces coplanar cause of approximation. Some more complexe workflow (many modifiers, rotation, scale…) could make that approximation error bigger.
How much should i put the treshold for error ? How many BU make it visible ?
Thanks again for your both answer (built-in and own function)

you need to add an acceptable error or margin for the calculations!


Yes and i don’t know what is acceptable :smiley:
By the way, i had a look at the apidoc for 2.62, looks like it moved to mathutils.geometry from geometry_utils.
I’ll do some testing to see if it that built-in function already has an error margin.
Otherwise i must do 2 test per vertecies (>-margin or < margin because it can return a negative value) and for models with 1 Million vertecies, it could be way too long…

Certainly matali you are welcome. The “acceptable” threshold is going to depend a lot on what you are doing. When do you consider your bank account at zero? If you are buying a house, $1000 is practically zero, but if you are buying a stamp, then $0.01 is effectively zero. So, I would make the precision a variable in your function so you can adapt it. You may want to make it a “relative” precision. Eg, 10^-5 the length of AB in your ABC plane

got this from 2.49

can you port may be
i’ll try if i have the time later on this night or tomorrow

import bpy, Blender
from Blender.Mathutils import TriangleNormal
def isCoplanar(verts):
    norm1 = TriangleNormal(verts[0].co, verts[1].co, verts[2].co)
    norm2 = TriangleNormal(verts[1].co, verts[2].co, verts[3].co)
    if 0.999999 &lt; abs(norm1.dot(norm2)) &lt; 1.000001:
        return True
        return False
ob = bpy.data.objects['Cube']
me = ob.getData(mesh=True)
for f in me.faces:
    if isCoplanar(f.verts):
        print "Face "+str(f.index)+" is coplanar"

you could make the margin a var here !


I like that idea of the relativness to the ABC distances :slight_smile:
By the way, could be great to speak in mm cm and m for that. How can i switch the metric system in my script ? I tried to copy the Ui function but it doesn’t work.
Thanks :slight_smile:

print (‘UnitSettings.system =’, bpy.context.scene.unit_settings.system)


Works :slight_smile: Thanks. And i didn’t see your post on the old 2.49 script. I’ll have a look to it and do some perf test compared to the build-in function if i’ve time.