and I don’t know how well things will work [python doesn’t have pointers, but objects are passed by refrence, so, are doubles passed by refrence? the code had them passed by pointer, so the behavior might not be the same]

however, the way blender subdivides a quad is pretty simple

the new vert on each of the edges is merely the midpoint of them

and the new vert in the center is merely the midpoint of the two new points on opposite edges [which pair of edges that is shouldn’t matter]

for triangles, there is no vert created in the middle, just the edges are subdivided

[and you can see pretty easy how things are filled simply by trying it, it would take me longer to explain than for you to do]

I understand you, but what i want to do is a script to divide the mesh by 3, 4, or more (i’m interested especialy in the impar numbers 3, 5,…) because it’s impossible in Blender.
It would be easier if all quads were planar, but they’re not, sometimes!!

That function is suposed to find the small line between other 2 lines (or give me 1st and 2nd points equal if the lines intersect).

With the code you give me, it’s easier for me to try to understand the function!!!

pa, pb, mua and mub are calculated inside the function, you can do 2 things to pass them to the program outside the function,

make them global

return them explicitely with a return statement at the end of the function.

My try:

from math import abs
## Calculate the line segment PaPb that is the shortest route between
## two lines P1P2 and P3P4. Calculate also the values of mua and mub where
## Pa = P1 + mua (P2 - P1)
## Pb = P3 + mub (P4 - P3)
def LineLineIntersect(p1,p2,p3,p4):
var = 0
p13, p43 = [0,0,0],[0,0,0]
p21 = [0,0,0]
p13[0] = p1[0] - p3[0]
p13[1] = p1[1] - p3[1]
p13[2] = p1[2] - p3[2]
p43[0] = p4[0] - p3[0]
p43[1] = p4[1] - p3[1];
p43[2] = p4[2] - p3[2];
if (abs(p43[0]) < EPS) and (abs(p43[1]) < EPS) and (abs(p43[2]) < EPS):
var = 0
else:
var = 1
p21[0] = p2[0] - p1[0];
p21[1] = p2[1] - p1[1];
p21[2] = p2[2] - p1[2];
if (abs(p21[0]) < EPS) and (abs(p21[1]) < EPS) and (abs(p21[2]) < EPS):
var = 0
else:
var = 1
d1343 = p13[0] * p43[0] + p13[1] * p43[1] + p13[2] * p43[2]
d4321 = p43[0] * p21[0] + p43[1] * p21[1] + p43[2] * p21[2]
d1321 = p13[0] * p21[0] + p13[1] * p21[1] + p13[2] * p21[2]
d4343 = p43[0] * p43[0] + p43[1] * p43[1] + p43[2] * p43[2]
d2121 = p21[0] * p21[0] + p21[1] * p21[1] + p21[2] * p21[2]
denom = d2121 * d4343 - d4321 * d4321
if (abs(denom) < EPS)
var = 0
else:
var = 1
numer = d1343 * d4321 - d1321 * d4343
mua = numer / denom
mub = (d1343 + d4321 * (mua)) / d4343
pa[0] = p1[0] + mua * p21[0]
pa[1] = p1[1] + mua * p21[1]
pa[2] = p1[2] + mua * p21[2]
pb[0] = p3[0] + mub * p43[0]
pb[1] = p3[1] + mub * p43[1]
pb[2] = p3[2] + mub * p43[2]
return var, pa, pb, mua, mub

If you supply the above function with four vectors it will return var together with pa, pb mua and mub.
From the value of var you can determine if the lines intersect or not, and if they do, pa and pb will be the same point in space.

I didn’t test this, but I’m fairly confident that it works.

On a side note, wouldn’t it be better if you first tried to code it yourself with the help of the info given at the page where you found the c-code?

i was referring to the other scripts at the start not yours and was only trying to point it out to the others how you dont need the math module for abs