Hello Brian,
I'm happy to hear that the script is interesting for you and that you think it is worth, to invest your time to improve it:-)
About the factories You are completly right. May I have a look in your actual code to understand what you are doing now?
The problem with square and n-gons may caused by the straight lines. Straight lines leads to colinear sampling points. That leads to two problems. the bisection planes between them are parallel. The intersection line is a tangent to our known universe;-) The second problem is that the normal vector (Hesse Normal Form) will be created by the cross product from these colinear (parallel) vectors. The result is a Null-Vector (magnitude and all components are Zero). That leads to a singulary matrix. I tried to catch that in the script with:
if(DetA!=0)
{
sp.x=DetX/DetA;
sp.y=DetY/DetA;
sp.z=DetZ/DetA;
} else {
sp.x=p1.x;
sp.y=p1.y;
sp.z=p1.z;
}
return sp;
The problem is, that I tried to return a wrong centerpoint as a workaround for straight line sections in the curve. (Something shoud be returned:-()
Later the length for the curvature vector will be calculated. Normally the vector to the Radius is diffrent from zero. Because I return p1, in that situation it is zero - an so it's magnitude, and what have I done - shit:
var d_vec=moi.vectorMath.createPoint(ptx[n+1].x-cp.x,ptx[n+1].y-cp.y,ptx[n+1].z-cp.z);
var magn=magnitude(d_vec);
var sf=scalefactor*1000.0;
var sd_vec=moi.vectorMath.createPoint((d_vec.x*sf/(magn*magn)),(d_vec.y*sf/(magn*magn)),(d_vec.z*sf/(magn*magn)));
d_vec is zero -> magn is zero -> and then I made a divide by zero op - maybe that kills your script! But sometimes it works, I can't retrace the problem - maybe caused by floating point precision(Attachment). A quick and dirty workaround would be to add a small value to sp before returning. Better catch the divide by zero or catch the whole calculation of collinar points - I don't know which way is the best. (For a better understanding the expression (magn*magn): the first scales the vector to a normalized one (lenght 1) - the second magn scales it to the curvature.)
Would you post your file with the killer square? Then I can make some experiments at the weekend:-)
I hope my speculations are right!???
Kind regards
Karsten
|