示例#1
0
        /// <summary>
        /// Applies a rotation transformation to this GRaff.Matrix.
        /// This is equivalent to Matrix.Rotation(a) * this.
        /// </summary>
        /// <param name="a">The angle to rotate by.</param>
        /// <returns>This GRaff.Matrix, after the transformation.</returns>
        public Matrix Rotate(Angle a)
        {
            double c = GMath.Cos(a), s = GMath.Sin(a);

            return(new Matrix(M00 * c - M10 * s, M01 * c - M11 * s, M02 * c - M12 * s,
                              M00 * s + M10 * c, M01 * s + M11 * c, M02 * s + M12 * c));
        }
示例#2
0
        public static Polygon Ellipse(Point center, double xRadius, double yRadius)
        {
            int precision = (int)GMath.Ceiling(GMath.Pi * GMath.Abs(xRadius + yRadius));

            if (precision <= 0)
            {
                return(new Polygon(new[] { center }));
            }
            double dt = GMath.Tau / precision;
            double c = GMath.Cos(dt), s = GMath.Sin(dt);

            double x = 1, y = 0, tmp;

            var pts = new Point[precision];

            for (int i = 0; i < precision; i++)
            {
                pts[i] = new Point(center.X + x * xRadius, center.Y + y * yRadius);

                tmp = x;
                x   = c * x - s * y;
                y   = s * tmp + c * y;
            }

            return(new Polygon(pts));
        }
示例#3
0
        public static Polygon Regular(int degree, double radius, Point center)
        {
            Contract.Requires <ArgumentOutOfRangeException>(degree >= 2);

            double dt = GMath.Tau / degree;
            double c = GMath.Cos(dt), s = GMath.Sin(dt);

            double x = 0, y = -radius, tmp;

            Point[] pts = new Point[degree];

            for (int i = 0; i < degree; i++)
            {
                pts[i] = new Point(center.X + x, center.Y + y);

                tmp = x;
                x   = c * x - s * y;
                y   = s * tmp + c * y;
            }

            return(new Polygon(pts));
        }
示例#4
0
 /// <summary>
 /// Creates a GRaff.Matrix representing a rotation transform around the origin.
 /// </summary>
 /// <param name="a">The angle to rotate by.</param>
 /// <returns>A new GRaff.Matrix representing the transformation.</returns>
 public static Matrix Rotation(Angle a)
 => new Matrix(GMath.Cos(a), -GMath.Sin(a), 0, GMath.Sin(a), GMath.Cos(a), 0);
示例#5
0
 public Vector Component(Angle direction)
 => new Vector(X * GMath.Cos(direction) + Y * GMath.Sin(direction), direction);
示例#6
0
 public Vector(double magnitude, Angle direction)
     : this()
 {
     X = magnitude * GMath.Cos(direction);
     Y = magnitude * GMath.Sin(direction);
 }