本文整理汇总了C#中Vector.DotProduct方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.DotProduct方法的具体用法?C# Vector.DotProduct怎么用?C# Vector.DotProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector
的用法示例。
在下文中一共展示了Vector.DotProduct方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DistanceToGround
public static float DistanceToGround(Vector observer, List<Quad> quads)
{
float closestGround = float.MaxValue;
Vector down = new Vector(0F, -1F, 0F);
foreach (Quad quad in quads)
{
Vector ab = quad.vertices[0].Difference(quad.vertices[1]);
Vector ac = quad.vertices[0].Difference(quad.vertices[2]);
Vector N = ab.CrossProduct(ac);
float d = -N.DotProduct(quad.vertices[0]);
float t = -(d + observer.DotProduct(N)) / (N.DotProduct(down));
if (t > 0)
t *= -1F;
float distance = (float)Math.Abs(t * down.Length());
Vector projection = observer.Difference(down.GetScaledVector(t));
if (!PointIsInQuad(projection, quad))
continue;
if (distance < closestGround)
closestGround = distance;
}
return closestGround;
}
示例2: AdjustPointToNotGoThroughQuad
public static bool AdjustPointToNotGoThroughQuad(float MinDistance, ref Vector observer, Quad quad)
{
Vector ab = quad.vertices[0].Difference(quad.vertices[1]);
Vector ad = quad.vertices[0].Difference(quad.vertices[3]);
Vector N = ab.CrossProduct(ad);
float d = -N.DotProduct(quad.vertices[0]);
float t = -(d + observer.DotProduct(N)) / (N.DotProduct(N));
float Distance = (float)Math.Abs(t * N.Length());
if (Distance > MinDistance)
return false; //too far away, regardless of where you are relative to the wall
Vector projectionOntoTriangle = new Vector(observer.x + t * N.x, observer.y + t * N.y, observer.z + t * N.z);
if (!PointIsInQuad(projectionOntoTriangle, quad))
return false; //outside the quad
//the point needs to be moved
float NormalMultiplier = MinDistance / N.Length();
if (N.x / (observer.x - projectionOntoTriangle.x) < 0
|| N.y / (observer.y - projectionOntoTriangle.y) < 0
|| N.z / (observer.z - projectionOntoTriangle.z) < 0)
NormalMultiplier *= -1.0F;
observer = new Vector(projectionOntoTriangle.x + N.x * NormalMultiplier, projectionOntoTriangle.y + N.y * NormalMultiplier, projectionOntoTriangle.z + N.z * NormalMultiplier);
return true;
}
示例3: DotProduct
public void DotProduct()
{
var a = new Vector(1, 0, 0);
var b = new Vector(0, 1, 0);
Assert.AreEqual(Math.PI / 2d, Math.Acos(a.DotProduct(b)));
a = new Vector(0, -1, 0);
b = new Vector(0, 1, 0);
Assert.AreEqual(Math.PI, Math.Acos(a.DotProduct(b)));
}
示例4: DotProduct
public void DotProduct()
{
var a = new Vector(1, 0, 0);
var b = new Vector(0, 1, 0);
Assert.That(System.Math.Acos(a.DotProduct(b)), Is.EqualTo(System.Math.PI / 2d));
a = new Vector(0, -1, 0);
b = new Vector(0, 1, 0);
Assert.That(System.Math.Acos(a.DotProduct(b)), Is.EqualTo(System.Math.PI));
}
示例5: ProjectPolygon
// Calculate the projection of a polygon on an axis and returns it as a [min, max] interval
public static void ProjectPolygon(Vector axis, Polygon polygon, ref float min, ref float max)
{
// To project a point on an axis use the dot product
float d = axis.DotProduct(polygon.Points[0]);
min = d;
max = d;
for (int i = 0; i < polygon.Points.Count; i++)
{
d = polygon.Points[i].DotProduct(axis);
if (d < min)
{
min = d;
}
else
{
if (d > max)
{
max = d;
}
}
}
}
示例6: PolygonCollision
// Check if polygon A is going to collide with polygon B for the given velocity
public static PolygonCollisionResult PolygonCollision(Polygon polygonA, Polygon polygonB, Vector velocity)
{
if (polygonA == null || polygonB == null)
{
Debug.Print("balls");
}
PolygonCollisionResult result = new PolygonCollisionResult();
result.Intersect = true;
result.WillIntersect = true;
int edgeCountA = polygonA.Edges.Count;
int edgeCountB = polygonB.Edges.Count;
float minIntervalDistance = float.PositiveInfinity;
Vector translationAxis = new Vector();
Vector edge;
// Loop through all the edges of both polygons
for (int edgeIndex = 0; edgeIndex < edgeCountA + edgeCountB; edgeIndex++)
{
if (edgeIndex < edgeCountA)
{
edge = polygonA.Edges[edgeIndex];
}
else
{
edge = polygonB.Edges[edgeIndex - edgeCountA];
}
// ===== 1. Find if the polygons are currently intersecting =====
// Find the axis perpendicular to the current edge
Vector axis = new Vector(-edge.Y, edge.X);
axis.Normalize();
// Find the projection of the polygon on the current axis
float minA = 0; float minB = 0; float maxA = 0; float maxB = 0;
ProjectPolygon(axis, polygonA, ref minA, ref maxA);
ProjectPolygon(axis, polygonB, ref minB, ref maxB);
// Check if the polygon projections are currentlty intersecting
if (IntervalDistance(minA, maxA, minB, maxB) > 0) result.Intersect = false;
// ===== 2. Now find if the polygons *will* intersect =====
// Project the velocity on the current axis
float velocityProjection = axis.DotProduct(velocity);
// Get the projection of polygon A during the movement
if (velocityProjection < 0)
{
minA += velocityProjection;
}
else
{
maxA += velocityProjection;
}
// Do the same test as above for the new projection
float intervalDistance = IntervalDistance(minA, maxA, minB, maxB);
if (intervalDistance > 0) result.WillIntersect = false;
// If the polygons are not intersecting and won't intersect, exit the loop
if (!result.Intersect && !result.WillIntersect) break;
// Check if the current interval distance is the minimum one. If so store
// the interval distance and the current distance.
// This will be used to calculate the minimum translation vector
intervalDistance = Math.Abs(intervalDistance);
if (intervalDistance < minIntervalDistance)
{
minIntervalDistance = intervalDistance;
translationAxis = axis;
Vector d = polygonA.Center - polygonB.Center;
if (d.DotProduct(translationAxis) < 0) translationAxis = -translationAxis;
}
}
// The minimum translation vector can be used to push the polygons appart.
// First moves the polygons by their velocity
// then move polygonA by MinimumTranslationVector.
if (result.WillIntersect) result.MinimumTranslationVector = translationAxis * minIntervalDistance;
return result;
}