示例#1
0
        public bool Intersect2DQuadrant(Vec3f point, byte quadrant)
        {
            switch (quadrant)
            {
            case 1:
                return(X > point.X && Y < point.Y);

            case 2:
                return(X < point.X && Y < point.Y);

            case 3:
                return(X < point.X && Y > point.Y);

            case 4:
                return(X > point.X && Y > point.Y);

            default:
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// Determine the angle between two <see cref="Vec3f"/>.
        /// </summary>
        /// <returns>The angle.</returns>
        /// <param name="from">From <see cref="Vec3f"/>.</param>
        /// <param name="to">To <see cref="Vec3f"/>.</param>
        public static float Angle(Vec3f from, Vec3f to)
        {
            float denominator = MathF.Sqrt(from.SqrtLength * to.SqrtLength);

            if (denominator < 0.1f)
            {
                return(0f);
            }
            float dot = Dot(from, to) / denominator;

            if (dot < -1.0f)
            {
                dot = -1.0f;
            }
            if (dot > 1.0f)
            {
                dot = 1.0f;
            }
            return(MathF.Acos(dot) * 1.0f / (MathF.PI * 2.0f / 360.0f));
        }
示例#3
0
 public static Vec3f Lerp(Vec3f from, Vec3f to, float value) => new Vec3f(
     Utility.Lerp(from.X, to.X, value),
     Utility.Lerp(from.Y, to.Y, value),
     Utility.Lerp(from.Z, to.Z, value)
     );
示例#4
0
 /// <summary>
 /// Determine the signed angle between two <see cref="Vec3f"/>.
 /// </summary>
 /// <returns>The signed angle.</returns>
 /// <param name="from">From <see cref="Vec3f"/>.</param>
 /// <param name="to">To <see cref="Vec3f"/>.</param>
 /// <param name="axis">Axis <see cref="Vec3f"/>.</param>
 public static float SignedAngle(Vec3f from, Vec3f to, Vec3f axis) => Angle(from, to) * Dot(axis, Cross(from, to)) >= 0.0f ? 1.0f : -1.0f;
示例#5
0
 /// <summary>
 /// Computes the cross product of this <see cref="Vec3f"/>
 /// and the <see cref="Vec3f"/> <c>b</c>, yielding
 /// a new <see cref="Vec3f"/>.
 /// </summary>
 /// <returns>The <see cref="Vec3f"/> that is this x <c>b</c>.</returns>
 /// <param name="a">The first <see cref="Vec3f"/> to multiply.</param>
 /// <param name="b">The second <see cref="Vec3f"/> to multiply.</param>
 public Vec3f Cross(Vec3f b) => Cross(this, b);
示例#6
0
 /// <summary>
 /// Computes the dot product of this <see cref="Vec3f"/>
 /// and the <see cref="Vec3f"/> <c>b</c>, yielding
 /// a new <see cref="Vec3f"/>.
 /// </summary>
 /// <returns>The <see cref="Vec3f"/> that is this * <c>b</c>.</returns>
 /// <param name="b">The <see cref="Vec3f"/> to multiply.</param>
 public float Dot(Vec3f b) => Dot(this, b);
示例#7
0
 /// <summary>
 /// Computes the cross product of the <see cref="Vec3f"/> <c>a</c>
 /// and the <see cref="Vec3f"/> <c>b</c>, yielding
 /// a new <see cref="Vec3f"/>.
 /// </summary>
 /// <returns>The <see cref="Vec3f"/> that is the <c>a</c> x <c>b</c>.</returns>
 /// <param name="b">The second <see cref="Vec3f"/> to multiply.</param>
 public static Vec3f Cross(Vec3f a, Vec3f b) => new Vec3f(a.Y * b.Z - a.Z * b.Y, a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X);
示例#8
0
 /// <summary>
 /// Computes the dot product of the <see cref="Vec3f"/> <c>a</c>
 /// and the <see cref="Vec3f"/> <c>b</c>, yielding
 /// a new <see cref="Vec3f"/>.
 /// </summary>
 /// <returns>The <see cref="Vec3f"/> that is the <c>a</c> * <c>b</c>.</returns>
 /// <param name="a">The <see cref="Vec3f"/> to multiply.</param>
 /// <param name="b">The <see cref="Vec3f"/> to multiply.</param>
 public static float Dot(Vec3f a, Vec3f b) => (a * b).Reduce;
示例#9
0
 /// <summary>
 /// Returns the <see cref="float"/> distance between this and another <see cref="Vec3f"/>
 /// </summary>
 /// <returns>The distance.</returns>
 /// <param name="b">End vector b.</param>
 public float Distance(Vec3f pointB) => Distance(this, pointB);
示例#10
0
 /// <summary>
 /// Returns the <see cref="float"/> distance between two <see cref="Vec3f"/>.
 /// </summary>
 /// <returns>The distance.</returns>
 /// <param name="a">Start vector a.</param>
 /// <param name="b">End vector b.</param>
 public static float Distance(Vec3f a, Vec3f b) => (a - b).Length;
示例#11
0
 /// <summary>
 /// Returns the center <see cref="Vec3f"/> between
 /// the current <see cref="Vec3f"/> and
 /// another <see cref="Vec3f"/> B.
 /// </summary>
 /// <returns>The center point.</returns>
 /// <param name="b">Vector b.</param>
 public Vec3f Center(Vec3f b) => Center(this, b);
示例#12
0
 /// <summary>
 /// Center <see cref="Vec3f"/> between two <see cref="Vec3f"/>.
 /// </summary>
 /// <returns>The center point.</returns>
 /// <param name="a">Vector a.</param>
 /// <param name="b">Vector b.</param>
 public static Vec3f Center(Vec3f a, Vec3f b) => (a + b) * 0.5f;