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); } if (Z < v.Z) { return(true); } if (Z > v.Z) { return(false); } return(false); }
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; } if (Z < min.Z) { Z = min.Z; } else if (max.Z < Z) { Z = max.Z; } }
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; } if (v.Z < min.Z) { v.Z = min.Z; } else if (max.Z < v.Z) { v.Z = max.Z; } return(v); }
public Obb3d(Obb3f v) { Center = new vector(v.Center); Extents = new vector(v.Extents); Ax = new vector(v.Ax); Ay = new vector(v.Ay); Az = new vector(v.Az); }
public Obb3d(aabb aabb) { Center = aabb.Center; Extents = aabb.Extents; Ax = vector.AxisX; Ay = vector.AxisY; Az = vector.AxisZ; }
public Obb3d(vector center, vector extents, vector ax, vector ay, vector az) { Center = center; Extents = extents; Ax = ax; Ay = ay; Az = az; }
/// <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 Range3d(vector min, vector max, bool normalize) { if (normalize) { vector.ElementWiseMinMax(min, max, out Min, out Max); } else { Min = min; Max = max; } }
public Range3d(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 Range3d(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; }
public void ElementWiseMaxSelf(vector v) { if (v.X > X) { X = v.X; } if (v.Y > Y) { Y = v.Y; } if (v.Z > Z) { Z = v.Z; } }
public void ElementWiseMinSelf(vector v) { if (v.X < X) { X = v.X; } if (v.Y < Y) { Y = v.Y; } if (v.Z < Z) { Z = v.Z; } }
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; } if (v2.Z < v1.Z) { v2.Z = v1.Z; } return(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 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; } ; if (v2.Z < v1.Z) { var t = v1.Z; v1.Z = v2.Z; v2.Z = t; } ; min = v1; max = v2; }
/// <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 Range3d(Range3f v) { Min = new vector(v.Min); Max = new vector(v.Max); }
public element Dot(vector v) { return(X * v.X + Y * v.Y + Z * v.Z); }
public Range3d(vector min, vector max) { Min = min; Max = max; }
public vector Cross(vector v) { return(new vector(Y * v.Z - Z * v.Y, Z * v.X - X * v.Z, X * v.Y - Y * v.X)); }
public void ExpandSelf(vector v) { Min.SubSelf(v); Max.AddSelf(v); }
public Range3d(vector position) { Min = position; Max = position; }
public void MergeSelf(vector v) { Min.ElementWiseMinSelf(v); Max.ElementWiseMaxSelf(v); }
public volume Expand(vector v) { return(new volume(Min - v, Max + v)); }
public volume Merge(vector v) { return(new volume(vector.ElementWiseMin(Min, v), vector.ElementWiseMax(Max, v))); }
public bool Contains(vector v) { return(Min <= v && v <= Max); }
public Aabb3d(Aabb3f v) { Center = new vector(v.Center); Extents = new vector(v.Extents); }
public Aabb3d(vector center, vector extents) { Center = center; Extents = extents; }
public bool Contains(vector v) { v.SubSelf(Center); return(Math.Abs(v.X) <= Extents.X && Math.Abs(v.Y) <= Extents.Y && Math.Abs(v.Z) <= Extents.Z); }