public Obb2d(vector center, vector extents, vector ax, vector ay) { Center = center; Extents = extents; Ax = ax; Ay = ay; }
public Obb2d(Obb2f v) { Center = new vector(v.Center); Extents = new vector(v.Extents); Ax = new vector(v.Ax); Ay = new vector(v.Ay); }
public Obb2d(aabb aabb) { Center = aabb.Center; Extents = aabb.Extents; Ax = vector.AxisX; Ay = vector.AxisY; }
/// <summary> /// 3次ベジェ曲線での補間を微分する /// </summary> /// <param name="t">パラメータ</param> /// <param name="p0">コントロールポイント0</param> /// <param name="p1">コントロールポイント1</param> /// <param name="p2">コントロールポイント2</param> /// <param name="p3">コントロールポイント3</param> /// <returns>微分結果のベクトル</returns> public static vector DiffInterpolate3(element t, vector p0, vector p1, vector p2, vector p3) { var t2 = t * t; var ti = 1 - t; var ti2 = ti * ti; return(p0 * (-3 * ti2) + p1 * (9 * t2 - 12 * t + 3) + p2 * (-9 * t2 + 6 * t) + p3 * (3 * t2)); }
/// <summary> /// 3次ベジェ曲線で補間する /// </summary> /// <param name="t">パラメータ</param> /// <param name="p0">コントロールポイント0</param> /// <param name="p1">コントロールポイント1</param> /// <param name="p2">コントロールポイント2</param> /// <param name="p3">コントロールポイント3</param> /// <returns>補間された座標</returns> public static vector Interpolate3(element t, vector p0, vector p1, vector p2, vector p3) { var t2 = t * t; var t3 = t2 * t; var ti = 1 - t; var ti2 = ti * ti; var ti3 = ti2 * ti; return(p0 * ti3 + p1 * (3 * ti2 * t) + p2 * (3 * ti * t2) + p3 * t3); }
public void ElementWiseMaxSelf(vector v) { if (v.X > X) { X = v.X; } if (v.Y > Y) { Y = v.Y; } }
public void ElementWiseMinSelf(vector v) { if (v.X < X) { X = v.X; } if (v.Y < Y) { Y = v.Y; } }
public bool Intersects(volume obb2) { volume obb1; if (this.IsAabb) { obb1 = obb2; obb2 = this; } else { obb1 = this; } var d = new vector(); var v = obb1.Center - obb2.Center; var eax = obb2.Ax * obb2.Extents.X; var eay = obb2.Ay * obb2.Extents.Y; var e1 = eax + eay; var e2 = eay - eax; d.X = Math.Abs(obb1.Ax.Dot(e1)); d.Y = Math.Abs(obb1.Ax.Dot(e2)); if (obb1.Extents.X + d.Max() < Math.Abs(obb1.Ax.Dot(v))) { return(false); } d.X = Math.Abs(obb1.Ay.Dot(e1)); d.Y = Math.Abs(obb1.Ay.Dot(e2)); if (obb1.Extents.Y + d.Max() < Math.Abs(obb1.Ay.Dot(v))) { return(false); } eax = obb1.Ax * obb1.Extents.X; eay = obb1.Ay * obb1.Extents.Y; e1 = eax + eay; e2 = eay - eax; d.X = Math.Abs(obb2.Ax.Dot(e1)); d.Y = Math.Abs(obb2.Ax.Dot(e2)); if (obb2.Extents.X + d.Max() < Math.Abs(obb2.Ax.Dot(v))) { return(false); } d.X = Math.Abs(obb2.Ay.Dot(e1)); d.Y = Math.Abs(obb2.Ay.Dot(e2)); if (obb2.Extents.Y + d.Max() < Math.Abs(obb2.Ay.Dot(v))) { return(false); } return(true); }
static bool PointInTriangle(vector2 p1, vector2 p2, vector2 p3, vector2 check) { var v1 = check - p1; var v2 = check - p2; var v3 = check - p3; var result1 = Side(v1, v2); var result2 = Side(v2, v3); var result3 = Side(v3, v1); return(result1 == result2 && result2 == result3); }
public Range2d(vector min, vector max, bool normalize) { if (normalize) { vector.ElementWiseMinMax(min, max, out Min, out Max); } else { Min = min; Max = max; } }
static public vector ElementWiseMax(vector v1, vector v2) { if (v2.X < v1.X) { v2.X = v1.X; } if (v2.Y < v1.Y) { v2.Y = v1.Y; } return(v2); }
public Range2d(IEnumerable <vector> positions) { vector min = vector.MaxValue, max = vector.MinValue; foreach (var p in positions) { min.ElementWiseMinSelf(p); max.ElementWiseMaxSelf(p); } Min = min; Max = max; }
public Range2d(IEnumerable <volume> volumes) { vector min = vector.MaxValue, max = vector.MinValue; foreach (var v in volumes) { min.ElementWiseMinSelf(v.Min); max.ElementWiseMaxSelf(v.Max); } Min = min; Max = max; }
static int Side(vector2 v1, vector2 v2) { var a = v1.X * v2.Y - v1.Y * v2.X; if (a < 0) { return(-1); } if (0 < a) { return(1); } return(0); }
public static void ElementWiseMinMax(vector v1, vector v2, out vector min, out vector max) { if (v2.X < v1.X) { var t = v1.X; v1.X = v2.X; v2.X = t; } ; if (v2.Y < v1.Y) { var t = v1.Y; v1.Y = v2.Y; v2.Y = t; } ; min = v1; max = v2; }
public vector this[int index] { get { switch (index) { case 0: return(P0); case 1: return(P1); case 2: return(P2); case 3: return(P3); default: throw new NotImplementedException(); } } set { switch (index) { case 0: P0 = value; break; case 1: P1 = value; break; case 2: P2 = value; break; case 3: P3 = value; break; default: throw new NotImplementedException(); } } }
public void ClipSelf(vector min, vector max) { if (X < min.X) { X = min.X; } else if (max.X < X) { X = max.X; } if (Y < min.Y) { Y = min.Y; } else if (max.Y < Y) { Y = max.Y; } }
public bool LessIdThan(vector v) { if (X < v.X) { return(true); } if (X > v.X) { return(false); } if (Y < v.Y) { return(true); } if (Y > v.Y) { return(false); } return(false); }
public vector Clip(vector min, vector max) { vector v = this; if (v.X < min.X) { v.X = min.X; } else if (max.X < v.X) { v.X = max.X; } if (v.Y < min.Y) { v.Y = min.Y; } else if (max.Y < v.Y) { v.Y = max.Y; } return(v); }
/// <summary> /// Use Newton-Raphson iteration to find better root. /// </summary> /// <param name="Q">Current fitted curve</param> /// <param name="P">Digitized point</param> /// <param name="u">Parameter value for <see cref="P"/></param> /// <returns>パラメータ</returns> static element NewtonRaphsonRootFind(cubicbezier Q, vector P, element u) { /* Compute Q(u) */ var Q_u = Q.Interpolate(u); /* Generate control vertices for Q' */ var Q1 = new vector[3]; /* Q' and Q'' */ for (int i = 0; i <= 2; i++) { Q1[i] = (Q[i + 1] - Q[i]) * 3; } /* Generate control vertices for Q'' */ var Q2 = new vector[2]; for (int i = 0; i <= 1; i++) { Q2[i] = (Q1[i + 1] - Q1[i]) * 2; } /* Compute Q'(u) and Q''(u) */ var Q1_u = Interpolate2(u, Q1[0], Q1[1], Q1[2]); var Q2_u = Interpolate1(u, Q2[0], Q2[1]); /* Compute f(u)/f'(u) */ var Q_u_P = Q_u - P; var numerator = Q_u_P.Dot(Q1_u); var denominator = Q1_u.LengthSquare + Q_u_P.Dot(Q2_u); if (denominator == 0) { return(u); } /* u = u - f(u)/f'(u) */ return(u - numerator / denominator); }
public volume Expand(vector v) { return(new volume(Min - v, Max + v)); }
public bool Contains(vector v) { v.SubSelf(Center); v = (Ax * v.X) + (Ay * v.Y); return(Math.Abs(v.X) <= Extents.X && Math.Abs(v.Y) <= Extents.Y); }
public Aabb2d(Aabb2f v) { Center = new vector(v.Center); Extents = new vector(v.Extents); }
public Aabb2d(vector center, vector extents) { Center = center; Extents = extents; }
public Range2d(Range2f v) { Min = new vector(v.Min); Max = new vector(v.Max); }
public Range2d(vector min, vector max) { Min = min; Max = max; }
public Range2d(vector position) { Min = position; Max = position; }
public void ExpandSelf(vector v) { Min.SubSelf(v); Max.AddSelf(v); }
public volume Merge(vector v) { return(new volume(vector.ElementWiseMin(Min, v), vector.ElementWiseMax(Max, v))); }
public void MergeSelf(vector v) { Min.ElementWiseMinSelf(v); Max.ElementWiseMaxSelf(v); }