Plane class bug?

Hi guys,

I noticed something very annoying… and I want to know if its a bug, or if there is some kind of mathematical logic behind such behavior.

When I construct a Plane given an origin point and two vectors, I get waaaay more decimal points than I need, thus producing some erroneous rounding that is making my code not work as expected.

below some code that explains this:


    double a = Math.Round(0.981179, 2);// a = 0.98
    double b = Math.Round(-0.193102, 2);// b = -0.19
    
    double c = Math.Round(0.951179, 2); // c = 0.95
    double d = Math.Round(-0.173102, 2);// d = -0.17
    
    Vector3d xAxis = new Vector3d(a, b, 0);// xAxis = {0.98,-0.19,0}
    Vector3d yAxis = new Vector3d(c, d, 0);//yAxis = {0.95,-0.17,0}
    
    Plane plane = new Plane(Point3d.Origin, xAxis, yAxis);
    
    
    A = plane.XAxis; // {0.98172,-0.190333,0} ???? Why??

// I am expecting it to be {0.98, -0.19,0} 


@DavidRutten, @dale , @piac do you guys know why this is happening??

any help here would be great !!

Hi @rawitscher-torres,

There is the calculation behind the Plane constructor you are using:

ON_Plane::CreateFromFrame

What you are seeing a a floating-point rounding errors. This is to be expected when working with floating point values. Here is some fun reading when you have time:

What Every Computer Scientist Should Know About Floating-Point Arithmetic

A bigger question is why are you throwing away numeric precision? What problem are you trying to solve?

– Dale

A = plane.XAxis; // {0.98172,-0.190333,0} ??? Why??

That’s not the floating point rounding, but the result of the xAxis being unitized inside the constructor.

Also your vectors of the xAxis and the yAxis are nearly parallel, which means yAxis will get modified a lot inside the constructor.