示例#1
0
        public SpaceTransformationHandler(Point3D newCenter, Point3D newPtOnZAxis)
        {
            //Calculate the unit normals along the three direction for the new system
            var n = new Vector3D
            {
                X = newPtOnZAxis.X - newCenter.X,
                Y = newPtOnZAxis.Y - newCenter.Y,
                Z = newPtOnZAxis.Z - newCenter.Z
            };

            n = n / n.Length;

            var v = new Vector3D {
                X = n.X, Y = n.Y + 10.0f, Z = n.Z
            };                                                          //A vector pointing a little higher than the first vector

            var u = Vector3D.CrossProduct(v, n);

            u = u / u.Length;

            v = Vector3D.CrossProduct(n, u);
            v = v / v.Length;

            double[,] rotatXonMatrXx = { { u.X, u.Y, u.Z, 0.0f }, { v.X, v.Y, v.Z, 0.0f }, { n.X, n.Y, n.Z, 0.0f }, { 0.0f, 0.0f, 0.0f, 1.0f } };

            double[,] translationMatrix = { { 1.0f, 0.0f, 0.0f, -newCenter.X }, { 0.0f, 1.0f, 0.0f, -newCenter.Y }, { 0.0f, 0.0f, 1.0f, -newCenter.Z }, { 0.0f, 0.0f, 0.0f, 1.0f } };

            _transformationMatrix = MatrixDataProcessor.MultiplyMatrices(rotatXonMatrXx, translationMatrix);
        }
示例#2
0
        public Point3D GetTransformedPoint(Point3D inP)
        {
            double[,] inputMatrix = { { inP.X }, { inP.Y }, { inP.Z }, { 1.0f } };

            var resultantMatrix = MatrixDataProcessor.MultiplyMatrices(_transformationMatrix, inputMatrix);
            var result          = new Point3D
            {
                X = resultantMatrix[0, 0],
                Y = resultantMatrix[1, 0],
                Z = resultantMatrix[2, 0]
            };

            return(result);
        }
        /// <summary>
        /// uses logic in Linear Regression.pdf to give a straight line based on the passed data points
        /// see "calculate line equation using linear regression.pdf" for calculation parameters
        /// </summary>
        /// <param name="xYPts"></param>
        /// <returns></returns>
        public static LineEquation2D Get2DStraightLineFromDataConstants(List <Point> xYPts)
        {
            //eqn form y = a + bx
            var n     = xYPts.Count;
            var sumX  = (xYPts.Select(pt => pt.X)).Sum();
            var sumY  = (xYPts.Select(pt => pt.Y)).Sum();
            var sumXx = (xYPts.Select(pt => pt.X * pt.X)).Sum();
            var sumXy = (xYPts.Select(pt => pt.X * pt.Y)).Sum();

            //n a    + sumX  b = sumY
            //sumX a + sumXX b = sumXY
            var coefficientMatrix = new[, ] {
                { n, sumX }, { sumX, sumXx }
            };
            var eqnConstants = new[] { sumY, sumXy };
            var result       = MatrixDataProcessor.SolveEquation(coefficientMatrix, eqnConstants);

            return(new LineEquation2D {
                M = result[1], C = result[0]
            });
        }