Ejemplo n.º 1
0
 public Ellipsoid(EllipsoidQuadraticForm ellipsoidQuadraticForm)
 {
     Requires.NotNull(ellipsoidQuadraticForm, "ellipsoidQuadraticForm");
     _quadraticForm = ellipsoidQuadraticForm;
     _parametricForm = ellipsoidQuadraticForm.EllipsoidParametricForm;
     XRadius = _parametricForm.XRadius;
     YRadius = _parametricForm.YRadius;
     ZRadius = _parametricForm.ZRadius;
     Xmax = _parametricForm.GetXmax();
     Ymax = _parametricForm.GetYmax();
     Zmax = _parametricForm.GetZmax();
     InverseTransform = _quadraticForm.AffineTransform;
     Poles = _parametricForm.GetPoles();
 }
Ejemplo n.º 2
0
        public EllipsoidQuadraticForm(double A, double B, double C, double D, double E, double F, double G, double H, double I, double J)
        {
            var doubleUtils = new DoubleUtils(1e-12);

            if (doubleUtils.Sign(A) < 0)
            {
                A = -A;
                B = -B;
                C = -C;
                D = -D;
                E = -E;
                F = -F;
                G = -G;
                H = -H;
                I = -I;
                J = -J;
            }
            Requires.Positive(doubleUtils.Sign(A), "A");
            Requires.Positive(doubleUtils.Sign(B), "B");
            Requires.Positive(doubleUtils.Sign(C), "C");
            Requires.Positive(doubleUtils.Sign(A * B - D * D), "A * B - D * D");
            Requires.Positive(doubleUtils.Sign(A * C - E * E), "A * C - E * E");
            Requires.Positive(doubleUtils.Sign(B * C - F * F), "B * C - F * F");
            _coefficients = new[] { A, B, C, D, E, F, G, H, I, J };
            QuadraticFrom = new[, ] {
                { A, D, E },
                { D, B, F },
                { E, F, C }
            };
            Offset = new[] { G, H, I, };

            var b = QuadraticFrom.Inverse().Multiply(Offset.Multiply(-1));
            var eigenDecomposition = new EigenvalueDecomposition(QuadraticFrom);
            var axisNumerator      = b.ElementwiseMultiply(QuadraticFrom.Multiply(b)).Sum() - J;
            var xradius            = System.Math.Sqrt(axisNumerator / eigenDecomposition.RealEigenvalues[0]);
            var yradius            = System.Math.Sqrt(axisNumerator / eigenDecomposition.RealEigenvalues[1]);
            var zradius            = System.Math.Sqrt(axisNumerator / eigenDecomposition.RealEigenvalues[2]);
            var rotation           = eigenDecomposition.Eigenvectors;

            EllipsoidParametricForm = new EllipsoidParametricForm(xradius, yradius, zradius, new Point3D(b[0], b[1], b[2]), rotation);

            var sqrt = rotation.Multiply(eigenDecomposition.DiagonalMatrix.Sqrt().Multiply(rotation.Inverse()));

            AffineTransform = sqrt.Multiply(1.0 / System.Math.Sqrt(axisNumerator));
        }
        public EllipsoidQuadraticForm(double A, double B, double C, double D, double E, double F, double G, double H, double I, double J)
        {
            var doubleUtils = new DoubleUtils(1e-12);
            if (doubleUtils.Sign(A) < 0) {
                A = -A;
                B = -B;
                C = -C;
                D = -D;
                E = -E;
                F = -F;
                G = -G;
                H = -H;
                I = -I;
                J = -J;
            }
            Requires.Positive(doubleUtils.Sign(A), "A");
            Requires.Positive(doubleUtils.Sign(B), "B");
            Requires.Positive(doubleUtils.Sign(C), "C");
            Requires.Positive(doubleUtils.Sign(A * B - D * D), "A * B - D * D");
            Requires.Positive(doubleUtils.Sign(A * C - E * E), "A * C - E * E");
            Requires.Positive(doubleUtils.Sign(B * C - F * F), "B * C - F * F");
            _coefficients = new[] { A, B, C, D, E, F, G, H, I, J };
            QuadraticFrom = new[,] {
                { A, D, E },
                { D, B, F },
                { E, F, C }
            };
            Offset = new[] { G, H, I, };

            var b = QuadraticFrom.Inverse().Multiply(Offset.Multiply(-1));
            var eigenDecomposition = new EigenvalueDecomposition(QuadraticFrom);
            var axisNumerator = b.ElementwiseMultiply(QuadraticFrom.Multiply(b)).Sum() - J;
            var xradius = System.Math.Sqrt(axisNumerator / eigenDecomposition.RealEigenvalues[0]);
            var yradius = System.Math.Sqrt(axisNumerator / eigenDecomposition.RealEigenvalues[1]);
            var zradius = System.Math.Sqrt(axisNumerator / eigenDecomposition.RealEigenvalues[2]);
            var rotation = eigenDecomposition.Eigenvectors;
            EllipsoidParametricForm = new EllipsoidParametricForm(xradius, yradius, zradius, new Point3D(b[0], b[1], b[2]), rotation);

            var sqrt = rotation.Multiply(eigenDecomposition.DiagonalMatrix.Sqrt().Multiply(rotation.Inverse()));
            AffineTransform = sqrt.Multiply(1.0 / System.Math.Sqrt(axisNumerator));
        }