예제 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <returns></returns>
 public static double Dot(Vec2d v0, Vec2d v1)
 {
     return(v0.X * v1.X + v0.Y * v1.Y);
 }
예제 #2
0
 /// <summary>
 /// Applies this transformation to the given point.
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 public Vec2d Apply(Vec2d point)
 {
     return(Rotation.Apply(point) + Translation);
 }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 public void Deconstruct(out OrthoBasis2d rotation, out Vec2d translation)
 {
     rotation    = Rotation;
     translation = Translation;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="vectors"></param>
 /// <param name="result"></param>
 /// <param name="mean"></param>
 /// <returns></returns>
 public static void GetCovarianceMatrix(this IEnumerable <Vec2d> vectors, Vec2d mean, double[] result)
 {
     DataUtil.GetCovarianceMatrix(vectors, mean, result);
 }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="origin"></param>
 /// <param name="x"></param>
 public Orient2d(Vec2d origin, Vec2d x)
 {
     Rotation    = new OrthoBasis2d(x);
     Translation = origin;
 }
예제 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <param name="factor"></param>
 /// <returns></returns>
 public Vec2d SlerpTo(Vec2d other, double factor)
 {
     return(SlerpTo(other, Angle(this, other), factor));
 }
예제 #7
0
 /// <summary>
 /// Returns paramters for the point of intersection between lines a and b.
 /// Returns false if there is no solution i.e. lines are parallel.
 /// </summary>
 /// <param name="startA"></param>
 /// <param name="endA"></param>
 /// <param name="startB"></param>
 /// <param name="endB"></param>
 /// <param name="ta"></param>
 /// <param name="tb"></param>
 public static bool LineLineIntersection(Vec2d startA, Vec2d endA, Vec2d startB, Vec2d endB, out double ta, out double tb)
 {
     return(LineLineIntersection(endA - startA, endB - startB, startB - startA, out ta, out tb));
 }
예제 #8
0
 /// <summary>
 /// Returns the reflection of v0 about v1.
 /// </summary>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <returns></returns>
 public static Vec2d Reflect(Vec2d v0, Vec2d v1)
 {
     //return Project(v0, v1) * 2.0 - v0;
     return(v1 * (Dot(v0, v1) / v1.SquareLength * 2.0) - v0);
 }
예제 #9
0
 /// <summary>
 /// Returns a vector parallel to v0 whos projection onto v1 equals v1
 /// </summary>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <returns></returns>
 public static Vec2d MatchProjection(Vec2d v0, Vec2d v1)
 {
     return(v1.SquareLength / Dot(v0, v1) * v0);
 }
예제 #10
0
 /// <summary>
 /// Returns the projection of v0 onto v1.
 /// </summary>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <returns></returns>
 public static Vec2d Project(Vec2d v0, Vec2d v1)
 {
     return(Dot(v0, v1) / v1.SquareLength * v1);
 }
예제 #11
0
 /// <summary>
 /// Returns the rejection of v0 onto v1.
 /// This is the perpendicular component of v0 with respect to v1.
 /// </summary>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <returns></returns>
 public static Vec2d Reject(Vec2d v0, Vec2d v1)
 {
     return(v0 - Project(v0, v1));
 }
예제 #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <returns></returns>
 public static double SignedAngle(Vec2d v0, Vec3d v1)
 {
     return(Math.Atan2(Cross(v0, v1), Dot(v0, v1)));
 }
예제 #13
0
 /// <summary>
 /// Returns the pseudo cross product calculated as the dot product between v1 and the perpendicular of v0.
 /// </summary>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <returns></returns>
 public static double Cross(Vec2d v0, Vec2d v1)
 {
     return(v0.X * v1.Y - v0.Y * v1.X);
 }
예제 #14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <returns></returns>
 public static double AbsDot(Vec2d v0, Vec2d v1)
 {
     return(Math.Abs(v0.X * v1.X) + Math.Abs(v0.Y * v1.Y));
 }
예제 #15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public double ManhattanDistanceTo(Vec2d other)
 {
     other.X -= X;
     other.Y -= Y;
     return(other.ManhattanLength);
 }
예제 #16
0
 /// <summary>
 /// Returns a vector parallel to v0 whose projection onto v2 equals the projection of v1 onto v2
 /// </summary>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <param name="v2"></param>
 /// <returns></returns>
 public static Vec2d MatchProjection(Vec2d v0, Vec2d v1, Vec2d v2)
 {
     return(Dot(v1, v2) / Dot(v0, v2) * v0);
 }
예제 #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <param name="factor"></param>
 /// <returns></returns>
 public Vec2d LerpTo(Vec2d other, double factor)
 {
     return(new Vec2d(
                X + (other.X - X) * factor,
                Y + (other.Y - Y) * factor));
 }
예제 #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <param name="factor"></param>
 /// <returns></returns>
 public static Vec2d Lerp(Vec2d v0, Vec2d v1, double factor)
 {
     return(v0.LerpTo(v1, factor));
 }
예제 #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <param name="factor"></param>
        /// <returns></returns>
        public Vec2d SlerpTo(Vec2d other, double angle, double factor)
        {
            double st = 1.0 / Math.Sin(angle);

            return(this * (Math.Sin((1.0 - factor) * angle) * st) + other * (Math.Sin(factor * angle) * st));
        }
예제 #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <param name="factor"></param>
 /// <returns></returns>
 public static Vec2d Slerp(Vec2d v0, Vec2d v1, double factor)
 {
     return(v0.SlerpTo(v1, Angle(v0, v1), factor));
 }
예제 #21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="startA"></param>
 /// <param name="deltaA"></param>
 /// <param name="startB"></param>
 /// <param name="deltaB"></param>
 /// <param name="ta"></param>
 /// <param name="tb"></param>
 public static bool LineLineIntersection2(Vec2d startA, Vec2d deltaA, Vec2d startB, Vec2d deltaB, out double ta, out double tb)
 {
     return(LineLineIntersection(deltaA, deltaB, startB - startA, out ta, out tb));
 }
예제 #22
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="v0"></param>
 /// <param name="v1"></param>
 /// <param name="angle"></param>
 /// <param name="factor"></param>
 /// <returns></returns>
 public static Vec2d Slerp(Vec2d v0, Vec2d v1, double angle, double factor)
 {
     return(v0.SlerpTo(v1, angle, factor));
 }
예제 #23
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rotation"></param>
 /// <param name="translation"></param>
 public Orient2d(OrthoBasis2d rotation, Vec2d translation)
 {
     Rotation    = rotation;
     Translation = translation;
 }
예제 #24
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <param name="tolerance"></param>
 /// <returns></returns>
 public bool ApproxEquals(Vec2d other, double tolerance = SlurMath.ZeroTolerance)
 {
     return
         (Math.Abs(other.X - X) < tolerance &&
          Math.Abs(other.Y - Y) < tolerance);
 }
예제 #25
0
 /// <summary>
 /// Inverts this transformation in place.
 /// </summary>
 public void Invert()
 {
     Rotation.Invert();
     Translation = -Rotation.Apply(Translation);
 }
예제 #26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <param name="tolerance"></param>
 /// <returns></returns>
 public bool ApproxEquals(Vec2d other, Vec2d tolerance)
 {
     return
         (Math.Abs(other.X - X) < tolerance.X &&
          Math.Abs(other.Y - Y) < tolerance.Y);
 }
예제 #27
0
 /// <summary>
 /// Applies the inverse of this transformation to the given point.
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 public Vec2d ApplyInverse(Vec2d point)
 {
     return(Rotation.ApplyInverse(point - Translation));
 }
예제 #28
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public double SquareDistanceTo(Vec2d other)
 {
     other.X -= X;
     other.Y -= Y;
     return(other.SquareLength);
 }
예제 #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="p0"></param>
 /// <param name="p1"></param>
 public static Orient2d CreateFromPoints(Vec2d p0, Vec2d p1)
 {
     return(new Orient2d(p0, p1 - p0));
 }
예제 #30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="vector"></param>
 /// <returns></returns>
 public static Vec2d Abs(Vec2d vector)
 {
     return(new Vec2d(Math.Abs(vector.X), Math.Abs(vector.Y)));
 }