/// <summary> /// Projection of a 2D-function <paramref name="f"/> onto a DG-Field /// </summary> public static void ProjectField(this DGField u, _2D f) { if (u.Basis.GridDat.SpatialDimension != 2) { throw new ArgumentException("mismatch in spatial dimension"); } u.ProjectField(f.Vectorize()); }
/// <summary> /// L2Error w.r.t. a 2D-function <paramref name="f"/> of a DG-Field /// </summary> public static double L2Error(this DGField u, _2D f) { if (u.Basis.GridDat.SpatialDimension != 2) { throw new ArgumentException("mismatch in spatial dimension"); } return(u.L2Error(f.Vectorize())); }
public static bool IsPointOnLine(_2D.Point point, _2D.Point lineStart, _2D.Point lineEnd) { double crossProd = (point.Y - lineStart.Y) * (lineEnd.X - point.X) - (point.X - lineStart.X) * (lineEnd.Y - lineStart.Y); if (Math.Abs(crossProd) > 0) return false; double dotProd = (point.X - lineStart.X) * (lineEnd.X - lineStart.X) + (point.Y - lineStart.Y) * (lineEnd.Y - lineStart.Y); if (dotProd < 0) return false; double lineLenSqr = _2D.Math2D.DistanceSquared(lineStart, lineEnd); if (dotProd > lineLenSqr) return false; return true; }
/// <summary> /// Vectorized 1D function (<see cref="ScalarFunction"/>) from a scalar implementation, with fixed time /// </summary> /// <param name="f">calling sequence: f(<paramref name="time"/>,x)</param> /// <param name="time">fixed time</param> /// <returns></returns> public static ScalarFunction Vectorize(this _2D f, double time) { return(delegate(MultidimensionalArray inp, MultidimensionalArray res) { int D = inp.GetLength(1); if (D != 1) { throw new ArgumentException("wrong spatial dimension."); } for (int i = 0; i < inp.GetLength(0); i++) { double x = inp[i, 0]; res[i] = f(time, x); } }); }
public static _2D.Point LineWithVectorIntersection(_2D.Point line1Start, _2D.Point line1End, _2D.Point line2Start, _2D.Point line2End) { _2D.Point p; double a1 = line1End.X - line1Start.X, a2 = line2End.Y - line2Start.Y; double b1 = line1Start.X - line1End.X, b2 = line2Start.X - line2End.X; double c1, c2; double det = a1 * b2 - a2 * b1; if (det == 0) return null; c1 = a1 * line1Start.X + b1 * line1Start.Y; c2 = a2 * line2Start.X + b2 * line2Start.Y; p = new _2D.Point((b2 * c1 - b1 * c2) / det, (a1 * c2 - a2 * c1) / det); if (p.X >= Math.Min(line1Start.X, line1End.X) && p.X <= Math.Max(line1Start.X, line1End.X) && p.Y >= Math.Min(line1Start.Y, line1End.Y) && p.Y <= Math.Max(line1Start.Y, line1End.Y)) return p; return null; }
public static _2D.Point ClosestPointOnLineFromPoint(_2D.Point point, _2D.Point lineStart, _2D.Point lineEnd) { double a1 = lineEnd.Y - lineStart.Y, b1 = lineStart.X - lineEnd.X; double c1 = (lineEnd.Y - lineStart.Y) * lineStart.X + (lineStart.X - lineEnd.X) * lineStart.Y; double c2 = (-1 * b1) * point.X + a1 * point.Y; double det = a1 * a1 + b1 * b1; double cx, cy; if (det != 0) { cx = (a1 * c1 - b1 * c2) / det; cy = (a1 * c2 + b1 * c1) / det; } else { cx = point.X; cy = point.Y; } return new _2D.Point(cx, cy); }
public static double Determinate(_2D.Vector v1, _2D.Vector v2) { return v1.X * v2.Y - v1.Y * v2.X; }
/// <summary> /// Scalar function conversion. /// </summary> public static Func <double[], double, double> Convert_tx2Xt(this _2D f) { return((double[] X, double t) => f(t, X[0])); }
/// <summary> /// Scalar function conversion. /// </summary> public static Func <double[], double> Convert_xy2X(this _2D f) { return((double[] X) => f(X[0], X[1])); }
public PowerupGenerator(_2D.Point center, double arenaHeight) { }
public MultiBallPowerup(Texture2D sprite, CollidableObjects.TriangleType triangleType, _2D.Point center, double width, double height) : base(sprite, triangleType, center, width, height) { _powerupColor = Microsoft.Xna.Framework.Color.Red; }