/// <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)); }
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)); }
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)); }
/// <summary> /// Returns whether this line intersects the other. /// Edge cases such as if the endpoint of one line lies on the other line /// have no definite behaviour. /// </summary> public bool Intersects(Line other) { var n = LeftNormal; var h = n.Dot(other.Origin - Origin); if (h * n.Dot(other.Destination - Origin) > 0) { return(false); } else if (h * n.Dot(other.Destination - Origin) == 0) { if ((Offset.Dot(other.Origin - Origin) < 0 && Offset.Dot(other.Destination - Origin) < 0) || (Offset.Dot(other.Origin - Destination) > 0 && Offset.Dot(other.Destination - Destination) > 0)) { return(false); } else { return(true); } } var angle = other.Offset.Angle(this.Offset); if (angle.Degrees == 0 || angle.Degrees == 180) { if (h != 0) { return(false); } return(_isPointAdjacent(other.Origin) || _isPointAdjacent(other.Destination)); } var sign = n.Dot(other.Offset) > 0 ? 1 : -1; var p = other.Origin - sign * new Vector(h / GMath.Sin(angle), angle); return(_isPointAdjacent(p)); }
/// <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);
public Vector Component(Angle direction) => new Vector(X * GMath.Cos(direction) + Y * GMath.Sin(direction), direction);
public Vector(double magnitude, Angle direction) : this() { X = magnitude * GMath.Cos(direction); Y = magnitude * GMath.Sin(direction); }