コード例 #1
0
ファイル: Line2D.cs プロジェクト: bclgenki/tvn-cosine
        public Line2D transform(TransformMatrix2D matrix)
        {
            Point2D startNew = matrix.multiply(start),
                    endNew   = matrix.multiply(end);

            return(new Line2D(startNew, endNew));
        }
コード例 #2
0
ファイル: Ellipse2D.cs プロジェクト: bclgenki/tvn-cosine
        public Point2D randomPoint()
        {
            double x     = Util.generateRandomDoubleBetween(-horizontalLength, horizontalLength);
            double delta = System.Math.Abs(verticalLength * System.Math.Sin(System.Math.Acos(x / horizontalLength)));
            double y     = Util.generateRandomDoubleBetween(-delta, delta);

            return(transformInverse.multiply(new Point2D(center.getX() + x, center.getY() + y)));
        }
コード例 #3
0
ファイル: Ellipse2D.cs プロジェクト: bclgenki/tvn-cosine
        public bool isInside(Point2D point)
        {
            Point2D transformedPoint = _transform.multiply(point);

            if (center.getX() - horizontalLength < transformedPoint.getX() && center.getX() + horizontalLength > transformedPoint.getX())
            {
                double delta = System.Math.Abs(verticalLength * System.Math.Sin(System.Math.Acos((transformedPoint.getX() - center.getX()) / horizontalLength)));
                return(transformedPoint.getY() < center.getY() + delta && transformedPoint.getY() > center.getY() - delta);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
ファイル: Ellipse2D.cs プロジェクト: bclgenki/tvn-cosine
        public IGeometric2D transform(TransformMatrix2D matrix)
        {
            Point2D  centerNew         = matrix.multiply(center);
            Vector2D horizontalNew     = centerNew.vec(matrix.multiply(center.add(horizontal))),
                     verticalNew       = centerNew.vec(matrix.multiply(center.add(vertical)));
            double radiusHorizontalNew = horizontalNew.length();
            double radiusVerticalNew   = verticalNew.length();

            if (Util.compareDoubles(radiusHorizontalNew, radiusVerticalNew))
            {
                //Transform let this ellipse become a circle.
                return(new Circle2D(centerNew, radiusHorizontalNew));
            }
            return(new Ellipse2D(centerNew, horizontalNew, verticalNew));
        }
コード例 #5
0
ファイル: Rect2D.cs プロジェクト: bclgenki/tvn-cosine
        public IGeometric2D transform(TransformMatrix2D matrix)
        {
            Point2D lowerLeftNew  = matrix.multiply(lowerLeft);
            Point2D upperRightNew = matrix.multiply(upperRight);
            Point2D upperLeftNew  = matrix.multiply(upperLeft);
            Point2D lowerRightNew = matrix.multiply(lowerRight);

            if (!Util.compareDoubles(lowerLeftNew.getY(), lowerRightNew.getY()) || !Util.compareDoubles(upperLeftNew.getY(), upperRightNew.getY()) || !Util.compareDoubles(lowerLeftNew.getX(), upperLeftNew.getX()) || !Util.compareDoubles(lowerRightNew.getX(), upperRightNew.getX()))
            {
                Point2D[] vertexes = new Point2D[4];
                vertexes[0] = lowerLeftNew;
                vertexes[1] = lowerRightNew;
                vertexes[2] = upperRightNew;
                vertexes[3] = upperLeftNew;
                return(new Polyline2D(vertexes, true));
            }
            return(new Rect2D(lowerLeftNew, upperRightNew));
        }
コード例 #6
0
ファイル: Polyline2D.cs プロジェクト: bclgenki/tvn-cosine
 public Polyline2D transform(TransformMatrix2D matrix)
 {
     Point2D[] vertexesNew = new Point2D[vertexes.Length];
     for (int i = 0; i < vertexes.Length; ++i)
     {
         vertexesNew[i] = matrix.multiply(vertexes[i]);
     }
     return(new Polyline2D(vertexesNew, _isClosed || (Util.compareDoubles(vertexesNew[0].getX(), vertexesNew[vertexes.Length - 1].getX()) && Util.compareDoubles(vertexesNew[0].getY(), vertexesNew[vertexes.Length - 1].getY()))));
 }
コード例 #7
0
        public IGeometric2D transform(TransformMatrix2D matrix)
        {
            Point2D  centerNew  = matrix.multiply(center);
            Point2D  maxXNew    = matrix.multiply(new Point2D(center.getX() + radius, center.getY()));
            Point2D  maxYNew    = matrix.multiply(new Point2D(center.getX(), center.getY() + radius));
            Vector2D vectorXNew = centerNew.vec(maxXNew);
            Vector2D vectorYNew = centerNew.vec(maxYNew);
            double   radiusXNew = vectorXNew.length();
            double   radiusYNew = vectorYNew.length();

            if (Util.compareDoubles(radiusXNew, radiusYNew))
            {
                //Transform let this circle stay a circle.
                return(new Circle2D(centerNew, radiusXNew));
            }
            if (Util.compareDoubles(maxXNew.getY(), centerNew.getY()) && Util.compareDoubles(maxYNew.getX(), centerNew.getX()))
            {
                //Transform let this circle become a ellipse, but it is not rotated.
                return(new Ellipse2D(centerNew, radiusXNew, radiusYNew));
            }
            //Transform let this circle become a rotated ellipse.
            return(new Ellipse2D(centerNew, vectorXNew, vectorYNew));
        }
コード例 #8
0
ファイル: Ellipse2D.cs プロジェクト: bclgenki/tvn-cosine
 /**
  * @param center the center point of the ellipse.
  * @param horizontal the horizontal radius of the ellipse as a vector.
  * @param vertical the vertical radius of the ellipse as a vector.
  */
 public Ellipse2D(Point2D center, Vector2D horizontal, Vector2D vertical)
 {
     this.center = center;
     if (Util.compareDoubles(horizontal.getX(), 0.0d) && Util.compareDoubles(vertical.getY(), 0.0d))
     {
         this.horizontal = vertical;
         this.vertical   = horizontal;
     }
     else
     {
         this.horizontal = horizontal;
         this.vertical   = vertical;
     }
     this.horizontalLength = this.horizontal.length();
     this.verticalLength   = this.vertical.length();
     if (Util.compareDoubles(this.horizontal.getY(), 0.0d) && Util.compareDoubles(this.vertical.getX(), 0.0d))
     {
         this.angle            = 0.0d;
         this._transform       = TransformMatrix2D.UNITY_MATRIX;
         this.transformInverse = TransformMatrix2D.UNITY_MATRIX;
     }
     else
     {
         if (Util.compareDoubles(this.horizontal.getX(), 0.0d))
         {
             this.angle = Vector2D.Y_VECTOR.angleTo(this.vertical);
         }
         else
         {
             this.angle = Vector2D.X_VECTOR.angleTo(this.horizontal);
         }
         TransformMatrix2D result = TransformMatrix2D.translate(center.getX(), center.getY());
         result                = result.multiply(TransformMatrix2D.rotate(-this.angle));
         this._transform       = result.multiply(TransformMatrix2D.translate(-center.getX(), -center.getY()));
         this.transformInverse = this._transform.inverse();
     }
 }