33using System.Runtime.InteropServices;
37 [StructLayout(LayoutKind.Sequential, Size = LineSegment.Size)]
38 [AdvBrowsableOrder(
"Vertex1,Vertex2")]
39#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !NETFX_CORE
50 div = 1 / ((v4.Y - v3.Y) * (v2.X - v1.X) - (v4.X - v3.X) * (v2.Y - v1.Y));
51 ua = ((v4.X - v3.X) * (v1.Y - v3.Y) - (v4.Y - v3.Y) * (v1.X - v3.X)) * div;
52 ub = ((v2.X - v1.X) * (v1.Y - v3.Y) - (v2.Y - v1.Y) * (v1.X - v3.X)) * div;
53 result = ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1;
58 div = 1 / ((v4.Y - v3.Y) * (v2.X - v1.X) - (v4.X - v3.X) * (v2.Y - v1.Y));
59 ua = ((v4.X - v3.X) * (v1.Y - v3.Y) - (v4.Y - v3.Y) * (v1.X - v3.X)) * div;
60 ub = ((v2.X - v1.X) * (v1.Y - v3.Y) - (v2.Y - v1.Y) * (v1.X - v3.X)) * div;
61 if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1)
83 Vector2D.
Dot(ref normal, ref ray.Direction, out dir);
89 Vector2D.
Dot(ref normal, ref originDiff, out actualDistance);
90 Scalar DistanceFromOrigin = -(actualDistance / dir);
91 if (DistanceFromOrigin >= 0)
94 Vector2D.
Multiply(ref ray.Direction, ref DistanceFromOrigin, out intersectPos);
95 Vector2D.
Add(ref intersectPos, ref originDiff, out intersectPos);
98 Vector2D.
Dot(ref intersectPos, ref tanget, out distanceFromSecond);
100 if (distanceFromSecond >= 0 && distanceFromSecond <= edgeMagnitude)
102 result = DistanceFromOrigin;
119 Scalar nProj = local.
Y * edge.
X - local.
X * edge.
Y;
120 Scalar tProj = local.
X * edge.
X + local.
Y * edge.
Y;
125 else if (tProj > edgeLength)
132 result = Math.Abs(nProj);
144 Scalar nProj = local.
Y * edge.
X - local.
X * edge.
Y;
145 Scalar tProj = local.
X * edge.
X + local.
Y * edge.
Y;
148 result = tProj * tProj + nProj * nProj;
150 else if (tProj > edgeLength)
153 result = tProj * tProj + nProj * nProj;
157 result = nProj * nProj;
166 [InstanceConstructor(
"Vertex1,Vertex2")]
169 this.Vertex1 = vertex1;
170 this.Vertex2 = vertex2;
211 return Equals(ref
this, ref other);
215 return Equals(ref line1, ref line2);
224 return Equals(ref line1, ref line2);
228 return !
Equals(ref line1, ref line2);
static Scalar Sqrt(Scalar d)
static void Intersects(ref Vector2D v1, ref Vector2D v2, ref Vector2D v3, ref Vector2D v4, out bool result)
Scalar GetDistance(Vector2D point)
LineSegment(Vector2D vertex1, Vector2D vertex2)
static void GetDistance(ref Vector2D vertex1, ref Vector2D vertex2, ref Vector2D point, out Scalar result)
static bool Intersects(ref Vector2D v1, ref Vector2D v2, ref Vector2D v3, ref Vector2D v4, out Vector2D result)
static void GetDistanceSq(ref Vector2D vertex1, ref Vector2D vertex2, ref Vector2D point, out Scalar result)
override bool Equals(object obj)
static bool operator==(LineSegment line1, LineSegment line2)
bool Equals(LineSegment other)
static bool Equals(ref LineSegment line1, ref LineSegment line2)
static bool Equals(LineSegment line1, LineSegment line2)
override int GetHashCode()
void Intersects(ref Ray ray, out Scalar result)
static void Intersects(ref Vector2D vertex1, ref Vector2D vertex2, ref Ray ray, out Scalar result)
void GetDistance(ref Vector2D point, out Scalar result)
override string ToString()
Scalar Intersects(Ray ray)
static bool operator!=(LineSegment line1, LineSegment line2)
This is the Vector Class.
static readonly Vector2D Zero
Vector2D(0,0)
static Vector2D Add(Vector2D left, Vector2D right)
Adds 2 Vectors2Ds.
static Vector2D GetRightHandNormal(Vector2D source)
Gets a Vector2D that is perpendicular(orthogonal) to the passed Vector2D while staying on the XY Plan...
static Vector2D Multiply(Vector2D source, Scalar scalar)
Does Scaler Multiplication on a Vector2D.
const int Size
The Size of the class in bytes;
Scalar X
This is the X value. (Usually represents a horizontal position or direction.)
static Scalar Dot(Vector2D left, Vector2D right)
Does a Dot Operation Also know as an Inner Product.
static Vector2D Normalize(Vector2D source)
This returns the Normalized Vector2D that is passed. This is also known as a Unit Vector.
override int GetHashCode()
Provides a unique hash code based on the member variables of this class. This should be done because ...
static Vector2D Subtract(Vector2D left, Vector2D right)
Subtracts 2 Vector2Ds.
Scalar Y
This is the Y value. (Usually represents a vertical position or direction.)
override bool Equals(object obj)
Compares this Vector to another object. This should be done because the equality operators (==,...
static Vector2D Lerp(Vector2D left, Vector2D right, Scalar amount)