|
In lugnet.cad.dev, Timothy Gould wrote:
// calc_z4 by Tore Eriksson
// credits to Ronan Webb for the superb formula
double calc_z4(double x1,double y1,double z1,
double x2,double y2,double z2,
double x3,double y3,double z3,
double x4,double y4)
{
double a,b,c,minus_d,z4;
a = y1*(z2-z3) + y2*(z3-z1) + y3*(z1-z2);
b = z1*(x2-x3) + z2*(x3-x1) + z3*(x1-x2);
c = x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2);
if(c==0)
{
err=11;
c=1;
}
minus_d = x1*(y2*z3-y3*z2) + x2*(y3*z1-y1*z3) + x3*(y1*z2-y2*z1);
z4 = (minus_d - a*x4 - b*y4)/c;
return z4;
}
>
> You also need a touch of code to catch when c=0 so that z4 is undefined ;)
>
> Tim
That shouldn't really be happening, unless someone enters a "triangle" that
isn't a triangle, for example with x1, x2, and x3 all = 0, or a line that isn't
referring to a polygon for some reason yet is processed as one.
Hmm, division by zero is not a thing to play with. I might add these 3 LOC's
anyway. Thanks for pointing this possible/hypothetical source of errors out.
/Tore
|
|
|
In lugnet.cad.dev, Tore Eriksson wrote:
> That shouldn't really be happening, unless someone enters a "triangle" that
> isn't a triangle, for example with x1, x2, and x3 all = 0, or a line that isn't
> referring to a polygon for some reason yet is processed as one.
Actually, if the original triangle is (for example) in the Y-Z plane, then just
passing in an x4 that's different from x1, x2, and x3 will result in a failure.
The equivalent goes for an initial triangle in the X-Z plane.
--Travis
|
|
|
In lugnet.cad.dev, Travis Cobbs wrote:
> In lugnet.cad.dev, Tore Eriksson wrote:
> > That shouldn't really be happening, unless someone enters a "triangle" that
> > isn't a triangle, for example with x1, x2, and x3 all = 0, or a line that isn't
> > referring to a polygon for some reason yet is processed as one.
>
> Actually, if the original triangle is (for example) in the Y-Z plane, then just
> passing in an x4 that's different from x1, x2, and x3 will result in a failure.
> The equivalent goes for an initial triangle in the X-Z plane.
>
> --Travis
True, but such triangles will not be visible in the 2-D front view of the UI and
therefor not clickable - unless the program is buggy. And if you can't click on
them, the function never has to encounter data from them. Hopefully...
/Tore
|
|
|