Пример #1
0
        public bool intersectWith(Line2D l, Vector2D o)
        {
            bool found = false;

            float a1, a2, b1, b2;

            // calculate slopes, deal with infinity
            if (End.X - Start.X == 0)
                b1 = (float)1e+10;
            else
                b1 = (End.Y - Start.Y) / (End.X - Start.X);

            if (l.End.X - l.Start.X == 0)
                b2 = (float)1e+10;
            else
                b2 = (l.End.Y - l.Start.Y) / (l.End.X - l.Start.X);

            // calculate position
            a1 = Start.Y - b1 * Start.X;
            a2 = l.Start.Y - b2 * l.Start.X;
            o.X = -(a1 - a2) / (b1 - b2);
            o.Y = a1 + b1 * o.X;

            // did the lines cross?
            if ((Start.X - o.X) * (o.X - End.X) >= -ROUNDING_ERROR_32 &&
                (l.Start.X - o.X) * (o.X - l.End.X) >= -ROUNDING_ERROR_32 &&
                (Start.Y - o.Y) * (o.Y - End.Y) >= -ROUNDING_ERROR_32 &&
                (l.Start.Y - o.Y) * (o.Y - l.End.Y) >= -ROUNDING_ERROR_32)
            {
                found = true;
            }
            return found;
        }
Пример #2
0
 public Vertex3D(Vector3D position, Vector3D normal, Color color, Vector2D tcoord)
     : this()
 {
     Position = position;
     Normal = normal;
     Color = color;
     TCoords = tcoord;
 }
Пример #3
0
 public void Set(Vector2D start, Vector2D end)
 {
     Start = start;
     End = end;
 }
Пример #4
0
        // Does this still work? (GetIntersectionWithSphere)
        public bool GetIntersectionWithCircle(Vector2D sorigin, float sradius, out double outdistance)
        {
            outdistance = 0.0;
            Vector2D q = sorigin - Start;
            double c = q.Length;
            Vector2D vv = Vector;
            vv.Normalize();
            double v = q.DotProduct(vv);
            double d = sradius * sradius - (c * c - v * v);

            if (d < 0.0)
                return false;

            outdistance = v - Math.Sqrt(d);
            return true;
        }
Пример #5
0
 public Line2D(float sX, float sY, float eX, float eY)
 {
     Start = new Vector2D();
     End = new Vector2D();
     Set(sX, sY, eX, eY);
 }
Пример #6
0
 public bool IsPointBetweenStartAndEnd(Vector2D point)
 {
     return point.IsBetweenPoints(Start, End);
 }
Пример #7
0
        public Vector2D GetClosestPoint(Vector2D point)
        {
            Vector2D c = point - Start;
            Vector2D v = End - Start;
            float d = v.Length;
            v = v / d;
            float t = v.DotProduct(c);

            if (t < 0.0f) return Start;
            if (t > d) return End;

            v = v * t;
            return Start + v;
        }
Пример #8
0
 //! Returns interpolated vector.
 /** \param other: other vector to interpolate between
 \param d: value between 0.0f and 1.0f. */
 public Vector2D GetInterpolated(Vector2D other, float d)
 {
     float inv = 1.0f - d;
     return new Vector2D(other.X * inv + X * d,
                     other.Y * inv + Y * d);
 }
Пример #9
0
 public void Set(Vector2D p) { X = p.X; Y = p.Y; }
Пример #10
0
 /// <summary>
 /// Returns squared distance from an other point.
 /// Here, the vector is interpreted as point in 3 dimensional space.
 /// </summary>
 public float GetDistanceFromSQ(Vector2D other)
 {
     float vx = X - other.X; float vy = Y - other.Y;
     return (vx * vx + vy * vy);
 }
Пример #11
0
 public Line2D(Vector2D start, Vector2D end)
 {
     Start = new Vector2D();
     End = new Vector2D();
     Set(start, end);
 }
Пример #12
0
 public float DotProduct(Vector2D other)
 {
     return X * other.X + Y * other.Y;
 }
Пример #13
0
 public double GetDistanceFrom(Vector2D other)
 {
     double vx = X - other.X; double vy = Y - other.Y;
     return Math.Sqrt(vx * vx + vy * vy);
 }
Пример #14
0
 public static Vector2D From(float x, float y)
 {
     Vector2D vect = new Vector2D();
     vect.X = x;
     vect.Y = y;
     return vect;
 }
Пример #15
0
 //! sets this vector to the interpolated vector between a and b.
 public void Interpolate(Vector2D a, Vector2D b, float t)
 {
     X = b.X + ((a.X - b.X) * t);
     Y = b.Y + ((a.Y - b.Y) * t);
 }
Пример #16
0
 public Vector2D GetInterpolated_Quadratic(Vector2D v2, Vector2D v3, float d)
 {
     float inv = 1.0f - d;
     float mul0 = inv * inv;
     float mul1 = 2.0f * d * inv;
     float mul2 = d * d;
     return new Vector2D(X * mul0 + v2.X * mul1 + v3.X * mul2,
         Y * mul0 + v2.Y * mul1 + v3.Y * mul2);
 }
Пример #17
0
 public void Set(float sX, float sY, float eX, float eY)
 {
     Start = new Vector2D(sX, sY);
     End = new Vector2D(eX, eY);
 }
Пример #18
0
 public Vertex3DTangents(Vector3D position, Vector3D normal, Color color,
                         Vector2D tcoord,
                         Vector3D binormal,
                         Vector3D tangent)
     : this()
 {
     Position = position;
     Normal = normal;
     Color = color;
     TCoords = tcoord;
     Binormal = binormal;
     Tangent = tangent;
 }
Пример #19
0
 /// <summary>
 /// Returns if the point represented by this vector is between to points
 ///</summary>
 ///<param name="begin">Start point of line</param>
 ///<param name="end">End point of line</param>
 ///<returns> True if between points, false if not. </returns>
 public bool IsBetweenPoints(Vector2D begin, Vector2D end)
 {
     float f = (end - begin).LengthSQ;
     return GetDistanceFromSQ(begin) < f && GetDistanceFromSQ(end) < f;
 }
Пример #20
0
        //! Calculates the angle between this vector and another one in grad.
        //! \return Returns a value between 0 and 90.
        public double GetAngleWith(Vector2D b)
        {
            double tmp = X * b.X + Y * b.Y;

            if (tmp == 0.0)
                return 90.0;

            tmp = tmp / Math.Sqrt((X * X + Y * Y) * (b.X * b.X + b.Y * b.Y));
            if (tmp < 0.0) tmp = -tmp;

            return Math.Atan(Math.Sqrt(1 - tmp * tmp) / tmp) * Math.PI;
        }
Пример #21
0
        public float GetPointOrientation(Vector2D point)
        {
            return ((End.X - Start.X) * (point.Y - Start.Y) - (point.X - Start.X) * (End.Y - Start.Y));


        }
Пример #22
0
        public bool IsPointOnLine(Vector2D point)
        {
            float d = GetPointOrientation(point);
            return (d == 0 && point.IsBetweenPoints(Start, End));

        }
Пример #23
0
        public static Matrix4 buildTextureTransform(float radians, Vector2D rotatecenter, Vector2D translate, Vector2D scale)
        {
            float c = NewMath.FCos(radians);
            float s = NewMath.FSin(radians);
            float[] M = new float[16];

            M[0] = (c * scale.X);
            M[1] = (s * scale.Y);
            M[2] = 0;
            M[3] = 0;

            M[4] = (-s * scale.X);
            M[5] = (c * scale.Y);
            M[6] = 0;
            M[7] = 0;

            M[8] = (c * scale.X * rotatecenter.X + -s * rotatecenter.Y + translate.X);
            M[9] = (s * scale.Y * rotatecenter.X + c * rotatecenter.Y + translate.Y);
            M[10] = 1;
            M[11] = 0;

            M[12] = 0;
            M[13] = 0;
            M[14] = 0;
            M[15] = 1;

            return Matrix4.From(M);
        }
Пример #24
0
        public void RotateBy(double degrees, Vector2D center)
        {
            degrees *= Math.PI / 180.0;
            float cs = NewMath.FCos(degrees);
            float sn = NewMath.FSin(degrees);
            X -= center.X;
            Y -= center.Y;

            Set(X * cs - Y * sn, X * sn + Y * cs);

            X += center.X;
            Y += center.Y;
        }