/// <summary> /// Returns the position of the first non-zero digit, after the /// decimal point. Note that the maximum return value is 10, /// which is a design decision in the implementation. /// </summary> /// <param name="step">The input value.</param> /// <returns>The position of the first non-zero digit.</returns> public static int StepDecimals(double step) { double[] sd = new double[] { 0.9999, 0.09999, 0.009999, 0.0009999, 0.00009999, 0.000009999, 0.0000009999, 0.00000009999, 0.000000009999, 0.0000000009999, 0.00000000009999, 0.000000000009999, 0.0000000000009999, 0.00000000000009999, 0.000000000000009999, }; double abs = Mathd.Abs(step); double decs = abs - (int)abs; // Strip away integer part for (int i = 0; i < sd.Length; i++) { if (decs >= sd[i]) { return(i); } } return(0); }
public Vector3d Intersect3(Planed b, Planed c) { double denom = _normal.Cross(b._normal).Dot(c._normal); if (Mathd.Abs(denom) <= Mathd.Epsilon) { return(new Vector3d()); } Vector3d result = b._normal.Cross(c._normal) * D + c._normal.Cross(_normal) * b.D + _normal.Cross(b._normal) * c.D; return(result / denom); }
public Vector3d IntersectSegment(Vector3d begin, Vector3d end) { Vector3d segment = begin - end; double den = _normal.Dot(segment); if (Mathd.Abs(den) <= Mathd.Epsilon) { return(new Vector3d()); } double dist = (_normal.Dot(begin) - D) / den; if (dist < -Mathd.Epsilon || dist > 1.0f + Mathd.Epsilon) { return(new Vector3d()); } return(begin + segment * -dist); }
public Vector3d IntersectRay(Vector3d from, Vector3d dir) { double den = _normal.Dot(dir); if (Mathd.Abs(den) <= Mathd.Epsilon) { return(new Vector3d()); } double dist = (_normal.Dot(from) - D) / den; // This is a ray, before the emitting pos (from) does not exist if (dist > Mathd.Epsilon) { return(new Vector3d()); } return(from + dir * -dist); }
/// <summary> /// Returns the result of the spherical linear interpolation between /// this quaternion and `to` by amount `weight`, but without /// checking if the rotation path is not bigger than 90 degrees. /// </summary> /// <param name="to">The destination quaternion for interpolation. Must be normalized.</param> /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> /// <returns>The resulting quaternion of the interpolation.</returns> public Quatd Slerpni(Quatd to, double weight) { double dot = Dot(to); if (Mathd.Abs(dot) > 0.9999f) { return(this); } double theta = Mathd.Acos(dot); double sinT = 1.0f / Mathd.Sin(theta); double newFactor = Mathd.Sin(weight * theta) * sinT; double invFactor = Mathd.Sin((1.0f - weight) * theta) * sinT; return(new Quatd ( invFactor * x + newFactor * to.x, invFactor * y + newFactor * to.y, invFactor * z + newFactor * to.z, invFactor * w + newFactor * to.w )); }
public Quatd Slerpni(Quatd b, double t) { double dot = Dot(b); if (Mathd.Abs(dot) > 0.9999f) { return(this); } double theta = Mathd.Acos(dot); double sinT = 1.0f / Mathd.Sin(theta); double newFactor = Mathd.Sin(t * theta) * sinT; double invFactor = Mathd.Sin((1.0f - t) * theta) * sinT; return(new Quatd ( invFactor * x + newFactor * b.x, invFactor * y + newFactor * b.y, invFactor * z + newFactor * b.z, invFactor * w + newFactor * b.w )); }
public bool IsNormalized() { return(Mathd.Abs(LengthSquared() - 1.0f) < Mathd.Epsilon); }
public Vector4d Abs() { return(new Vector4d(Mathd.Abs(x), Mathd.Abs(y), Mathd.Abs(z), Mathd.Abs(w))); }
/// <summary> /// Returns a new vector with all components in absolute values (i.e. positive). /// </summary> /// <returns>A vector with <see cref="Mathd.Abs(double)"/> called on each component.</returns> public Vector2d Abs() { return(new Vector2d(Mathd.Abs(x), Mathd.Abs(y))); }
/// <summary> /// Returns whether the quaternion is normalized or not. /// </summary> /// <returns>A bool for whether the quaternion is normalized or not.</returns> public bool IsNormalized() { return(Mathd.Abs(LengthSquared - 1) <= Mathd.Epsilon); }
public bool HasPoint(Vector3d point, double epsilon = Mathd.Epsilon) { double dist = _normal.Dot(point) - D; return(Mathd.Abs(dist) <= epsilon); }
/// <summary> /// Returns a new vector with all components in absolute values (i.e. positive). /// </summary> /// <returns>A vector with <see cref="Mathd.Abs(double)"/> called on each component.</returns> public Vector3d Abs() { return(new Vector3d(Mathd.Abs(x), Mathd.Abs(y), Mathd.Abs(z))); }