Пример #1
0
        public static Vector2 RotateAround(Vector2 axis, Vector2 v, AngleF angle)
        {
            if (angle.Degrees == 0)
            {
                return(v);
            }

            return(RotateAroundAxis(axis.X, axis.Y, v.X, v.Y, angle));
        }
Пример #2
0
        public static Vector2 Rotate(Vector2 v, AngleF angle)
        {
            if (angle.Degrees == 0)
            {
                return(v);
            }

            return(Rotate(v.X, v.Y, angle));
        }
Пример #3
0
 public static Vector2 Rotate(float x, float y, AngleF angle)
 {
     return(angle.Degrees switch
     {
         0 => new Vector2(x, y),
         90 => Rotate90(x, y),
         180 => Rotate180(x, y),
         270 => Rotate270(x, y),
         _ => new Vector2(
             x * MathF.Cos(angle.Radians) - (y * MathF.Sin(angle.Radians)),
             x * MathF.Sin(angle.Radians) + (y * MathF.Cos(angle.Radians)))
     });
Пример #4
0
        public static ImmutableColor FromHsv(AngleF h, float s, float v)
        {
            if (!RangeF.Percent.All(s, v))
            {
                throw new ArgumentException("One of the specified float values are out of range.");
            }

            float c = v * s;
            float x = c * (1 - Math.Abs((h.Degrees / 60.00f) % 2 - 1));
            float m = v - c;

            return(CreateFromChmx(c, h.Degrees, m, x));
        }
Пример #5
0
        public static ImmutableColor FromHsl(AngleF hue, float s, float l)
        {
            if (!RangeF.Percent.All(s, l))
            {
                throw new ArgumentException("One of the specified float values are out of range.");
            }

            float c = (1 - Math.Abs((2 * l) - 1)) * s;
            float x = c * (1 - Math.Abs((hue.Degrees / 60.00f) % 2 - 1));
            float m = l - (c / 2);

            return(CreateFromChmx(c, hue.Degrees, m, x));
        }
Пример #6
0
 public void OffsetRotate(AngleF offset)
 {
     X = X * MathF.Cos(offset.Radians) - (Y * MathF.Sin(offset.Radians));
     Y = Y * MathF.Sin(offset.Radians) + (Y * MathF.Cos(offset.Radians));
 }
Пример #7
0
        public static Vector2 RotateAroundAxis(float ax, float ay, float vx, float vy, AngleF angle)
        {
            float   x       = vx - ax;
            float   y       = vy - ay;
            Vector2 rotated = Rotate(x, y, angle);

            return(new Vector2(ax + rotated.X, ay + rotated.Y));
        }
Пример #8
0
 public static IEnumerable <Vector2> RotateAround(Vector2 axis, IEnumerable <Vector2> set, AngleF angle)
 {
     foreach (Vector2 v in set)
     {
         yield return(RotateAround(axis, v, angle));
     }
 }
Пример #9
0
 public static Vector2 PolarToParametric(float magnitude, AngleF direction)
 {
     return(new Vector2(magnitude * MathF.Cos(direction.Radians),
                        magnitude * MathF.Sin(direction.Radians)));
 }