コード例 #1
0
        public static PointModel CalculatePointByTwoLines(LineModel lineA, LineModel lineB)
        {
            var x = (lineB.b - lineA.b) / (lineA.a - lineB.a);
            var y = lineA.CalculateY(x);

            return(new PointModel(x, y));
        }
コード例 #2
0
        private void DrawLineByLine(ref Graphics graphic, Pen pen, LineModel line)
        {
            var        maxY = line.CalculateY(maxCoordinateSystemLength);
            PointModel maxNegativePoint, maxPositivePoint;

            if (Math.Abs(maxY) > maxCoordinateSystemLength)
            {
                maxNegativePoint = new PointModel(line.CalculateX(-1 * maxCoordinateSystemLength), -1 * maxCoordinateSystemLength);
                maxPositivePoint = new PointModel(line.CalculateX(maxCoordinateSystemLength), maxCoordinateSystemLength);
            }
            else
            {
                maxNegativePoint = new PointModel(-1 * maxCoordinateSystemLength, line.CalculateY(-1 * maxCoordinateSystemLength));
                maxPositivePoint = new PointModel(maxCoordinateSystemLength, line.CalculateY(maxCoordinateSystemLength));
            }

            DrawLineByPoint(ref graphic, pen, maxNegativePoint, maxPositivePoint);
        }
コード例 #3
0
        public static double CalculateDirectionFromLine(LineModel line)
        {
            var throughZeroLine = new LineModel(line.a, 0, line.lineDirection);

            double x = 100.00;
            var    y = throughZeroLine.CalculateY(x);

            if (y == 0)
            {
                return(0);
            }

            var tan   = Math.Abs(x / y);
            var angle = MathOperation.TanH(tan);

            if (line.a > 0)
            {
                var direction = angle;
                if (line.lineDirection == LineDirection.RIGHT_TO_LEFT)
                {
                    direction = direction + 180;
                }

                if (direction > 360)
                {
                    direction = direction - 360;
                }

                return(Math.Round(direction, 2));
            }
            else
            {
                var direction = 360 - angle;
                if (line.lineDirection == LineDirection.LEFT_TO_RIGHT)
                {
                    direction = direction - 180;
                }

                if (direction > 360)
                {
                    direction = direction - 360;
                }

                return(Math.Round(direction, 2));
            }
        }
コード例 #4
0
        public static PointModel CalculatePointByLineAndLength(LineModel line, PointModel point, double length, LineDirection direction)
        {
            double x2;

            if (direction == LineDirection.LEFT_TO_RIGHT)
            {
                x2 = point.x + length / Math.Sqrt(1 + line.a * line.a);
            }
            else
            {
                x2 = point.x - length / Math.Sqrt(1 + line.a * line.a);
            }
            double y2 = line.CalculateY(x2);

            PointModel result = new PointModel(x2, y2);

            return(result);
        }