本文整理汇总了C#中Vector.Dot方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.Dot方法的具体用法?C# Vector.Dot怎么用?C# Vector.Dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector
的用法示例。
在下文中一共展示了Vector.Dot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDotProductNonOrthogonal
public void TestDotProductNonOrthogonal()
{
var v1 = new Vector<string, int> { { "x", 1 }, { "y", 2 } };
var v2 = new Vector<string, int> { { "x", 3 }, { "y", -4 } };
int d = v1.Dot(v2);
d.ShouldEqual(-5);
}
示例2: SetNormalAndPoint
public void SetNormalAndPoint(Vector normal, Vector point)
{
_normal = normal;
_normal.Normalize();
_point = point;
_distance = -_normal.Dot(_point);
}
示例3: Compute
public double Compute(Vector x, Vector y)
{
if (x.Length != y.Length)
throw new InvalidOperationException("Cannot compute similarity between two unequally sized Vectors!");
var xSum = x.Sum();
var ySum = y.Sum();
return (x.Dot(y) - ((xSum * ySum) / x.Length)) / System.Math.Sqrt(((x ^ 2).Sum() - (System.Math.Pow(xSum, 2) / x.Length)) * ((y ^ 2).Sum() - (System.Math.Pow(ySum, 2) / y.Length)));
}
示例4: DotMultiplication
public void DotMultiplication()
{
var v1 = new Vector(1, 1, 1);
var v2 = new Vector(1, 1, 1);
var resul = v1.Dot(v2);
Assert.AreEqual(3, resul);
}
示例5: SetVectors
public void SetVectors(Vector vector1, Vector vector2, Vector vector3)
{
_vector1 = vector1;
_vector2 = vector2;
_vector3 = vector3;
var aux1 = vector1 - vector2;
var aux2 = vector3 - vector2;
_normal = aux2 * aux1;
_normal.Normalize();
_point = vector2;
_distance = -_normal.Dot(_point);
}
示例6: TriangleObj
/**
* TriangleObj
*
* @param objmaterial
* @param newobjID
* @param numverts
* @param vertices
* @param MaxX
* @param MinX
* @param MaxY
* @param MinY
* @param MaxZ
* @param MinZ
*/
public TriangleObj (Material objmaterial, int newobjID, int numverts, Point[] vertices, Point max, Point min)
: base (objmaterial, newobjID, numverts, vertices, max, min)
{
Vector[] temp = new Vector[3];
for (int i = 0; i < 3; i++) {
temp [i] = new Vector (vertices [i].GetX (), vertices [i].GetY (), vertices [i].GetZ ());
}
S1 = new Vector ();
S2 = new Vector ();
S3 = new Vector ();
S1.Cross (temp [1], temp [2]);
S2.Cross (temp [2], temp [0]);
S3.Cross (temp [0], temp [1]);
double delta = 1.0f / S1.Dot (temp [0]);
S1.Scale (delta * S1.Length ());
S2.Scale (delta * S2.Length ());
S3.Scale (delta * S3.Length ());
}
示例7: Tick
//.........这里部分代码省略.........
float oldarea = Geometry.CalculateArea(contactrgn);
if (newarea < oldarea)
continue;
}
// Calculate contact point, and relative velocities.
// Make a 1000 unit normal so that we can use ints.
Vector collNormal = new Vector(MathEx.Round(normal.X * 1000),
MathEx.Round(normal.Y * 1000));
double collNormalLength = collNormal.Length;
if (collNormalLength == 0)
continue;
// Find the relative velocity at the collision point.
Vector rvBodies = new Vector(MathEx.Round(body1.Vx - body2.Vx),
MathEx.Round(body1.Vy - body2.Vy));
// Add in the velocity due to rotation of the bodies.
Vector cgToContact1 = Vector.FromPoints(body1.CG, contactPoint);
Vector orthoToCG1 = new Vector(-cgToContact1.DY, cgToContact1.DX);
Vector cgToContact2 = Vector.FromPoints(body2.CG, contactPoint);
Vector orthoToCG2 = new Vector(-cgToContact2.DY, cgToContact2.DX);
Vector rv = rvBodies + orthoToCG1 * body1.Va - orthoToCG2 * body2.Va;
CollisionResponse cr = new CollisionResponse();
cr.body = body2;
cr.collidingBody = body1;
cr.contactpoint = contactPoint;
// Take the smaller of the two elasticities for the collision.
double elasticity = Math.Min(body1.elasticity, body2.elasticity);
// Calculate the change in velocity times mass.
// These formulas come from _Physics for Game Developers_ by Bourg, p 98.
double impulseTimesMass = 0;
if (body1.anchored && collNormalLength > 0)
{
impulseTimesMass = (1 + elasticity) * rv.Dot(collNormal) /
(1/ body2.Mass +
Math.Abs(collNormal.Dot(orthoToCG2) * Vector.Cross(cgToContact2, collNormal)) /
body2.I / 1e6 / collNormal.LengthSq) /
collNormalLength;
}
else if (collNormalLength > 0)
{
impulseTimesMass = (1 + elasticity) * rv.Dot(collNormal) /
(1/body1.Mass + 1/body2.Mass +
Math.Abs(collNormal.Dot(orthoToCG1) * Vector.Cross(cgToContact1, collNormal)) /
body1.I / 1e6 / collNormal.LengthSq +
Math.Abs(collNormal.Dot(orthoToCG2) * Vector.Cross(cgToContact2, collNormal)) /
body2.I / 1e6 / collNormal.LengthSq) /
collNormalLength;
}
// Force that will result in that change in velocity.
cr.impulseforce = collNormal * (impulseTimesMass / dt / collNormalLength);
// Add sliding friction for ellipses colliding with polygons.
if (!body2.anchored && body2 is EllipticalBody && body1 is PolygonalBody)
{
// Figure out the velocity parallel to the normal.
double velocityNormal = rvBodies.Dot(collNormal) / collNormalLength;
// The frictional force is proportional to that.
// Note: For some reason, a coefficient of friction of 1.0
// sometimes creates a singularity.
double cfriction = Math.Min(body2.cfriction, .99);
double frictionForceMagnitude =
Math.Abs(velocityNormal) * cfriction * body2.Mass / dt;
// Figure out the velocity orthogonal to the normal.
Vector orthoNormal = new Vector(collNormal.DY, -collNormal.DX);
double velocityOrtho = -rv.Dot(orthoNormal) / collNormalLength;
// You can't have a frictional force that actually reverses the velocity.
double maximumForce = Math.Abs(velocityOrtho * body2.Mass / dt);
try
{
// The frictional force will be along the orthogonal to the normal,
// in the opposite direction of the velocity.
Vector frictionForce = orthoNormal * (-Math.Sign(velocityOrtho) *
Math.Min(frictionForceMagnitude, maximumForce)) / collNormalLength;
// Add friction.
cr.impulseforce += frictionForce;
}
catch (ArithmeticException ex)
{
Console.WriteLine("Silding friction exception: " + ex.ToString());
}
}
collisions.Add(cr);
}
}
}
示例8: FindIntersection
// For now, just return whether collision has occurred.
private bool FindIntersection(RigidBodyBase body1, RigidBodyBase body2,
out Point contactPoint, out PointF normal)
{
// Initialize out variables.
contactPoint = new Point(0, 0);
normal = new PointF(0, 0);
if (!body1.BoundingBox.IntersectsWith(body2.BoundingBox))
return false;
if (ConnectedByJoint(body1, body2))
return false;
Point[] vertices1, vertices2;
if (body1 is PolygonalBody)
{
vertices1 = (Point[])((PolygonalBody)body1).Vertices.Clone();
body1.displacement.TransformPoints(vertices1);
}
else
{
// Approximate vertices for ellipse.
vertices1 = ((EllipticalBody)body1).GetPoints();
}
if (body2 is PolygonalBody)
{
vertices2 = (Point[])((PolygonalBody)body2).Vertices.Clone();
body2.displacement.TransformPoints(vertices2);
}
else
{
// Approximate vertices for ellipse.
vertices2 = ((EllipticalBody)body2).GetPoints();
}
// Loop through each segment and look for intersections.
ArrayList intersections = new ArrayList();
for (int i = 0; i < vertices1.Length; i++)
{
for (int j = 0; j < vertices2.Length; j++)
{
double tAB, tPQ;
Point v1 = vertices1[i];
Point v1Next = vertices1[(i + 1) % vertices1.Length];
Point v2 = vertices2[j];
Point v2Next = vertices2[(j + 1) % vertices2.Length];
bool hit = SegmentCollision.HitTest(v1, v1Next, v2, v2Next,
out tAB, out tPQ);
if (hit)
{
// Find intersections from here.
Point intersection = new Point((int)(v1.X + (v1Next.X - v1.X) * tAB),
(int)(v1.Y + (v1Next.Y - v1.Y) * tAB));
intersections.Add(intersection);
}
}
}
// If no intersections, then no collisions.
if (intersections.Count == 0)
return false;
// Get average intersection.
int sumX = 0;
int sumY = 0;
foreach (Point intersection in intersections)
{
sumX += intersection.X;
sumY += intersection.Y;
}
contactPoint = new Point(sumX / intersections.Count,
sumY / intersections.Count);
// Find normal by constructing orthogonal vector from first/last intersections.
// Note: this can be improved by doing a linear fit through the intersections.
Point i0 = (Point)intersections[0];
Point i1 = (Point)intersections[intersections.Count - 1];
// Create a normal vector.
Vector normalVec = new Vector(i1.Y - i0.Y, i0.X - i1.X);
// Compare to vector between contact point and body1.
Vector collToBody1 =
new Vector(contactPoint.X - body1.CG.X, contactPoint.Y - body1.CG.Y);
// If in the opposite direction, reverse normal.
if (collToBody1.Dot(normalVec) < 0)
normalVec = normalVec * -1.0;
// Normalize.
double normalLength = normalVec.Length;
if (normalLength > 0)
normal = new PointF((float)(normalVec.DX / normalLength),
(float)(normalVec.DY / normalLength));
else
normal = new PointF(0, 0);
//.........这里部分代码省略.........
示例9: OnGizmoMoved
/// <summary>
/// Callback method when gizmo is moved by user action.
/// </summary>
/// <param name="gizmoInAction">Gizmo that moved.</param>
/// <param name="offset">Offset by which the gizmo has moved.</param>
protected override void OnGizmoMoved(IGizmo gizmoInAction, Vector offset)
{
var offsetPos = origin.Add(offset);
origin.Dispose();
origin = offsetPos;
foreach (var item in indexedAxisNodePairs)
{
// When more than one input is connected to the same slider, this
// method will decompose the axis corresponding to each input.
using (var v = GetFirstAxisComponent(item.Value.Item1))
{
var amount = offset.Dot(v);
if (Math.Abs(amount) > 0.001)
{
ModifyInputNode(item.Value.Item2, amount);
}
}
}
}
示例10: DotProductShouldWork
public static void DotProductShouldWork()
{
var v0 = new Vector(0, 1);
v0.Dot(v0.UnitNormal).Should().Be(0);
}
示例11: Compute
public double Compute(Vector x, Vector y)
{
double dot = x.Dot(y);
return dot / (System.Math.Pow(x.Norm(), 2) + System.Math.Pow(y.Norm(), 2) - dot);
}
示例12: OnGizmoMoved
/// <summary>
/// Callback method when gizmo is moved by user action.
/// </summary>
/// <param name="gizmo">Gizmo that moved.</param>
/// <param name="offset">Offset by which the gizmo has moved.</param>
/// <returns>New expected position of the Gizmo</returns>
protected override Point OnGizmoMoved(IGizmo gizmo, Vector offset)
{
expectedPosition = origin.Add(offset);
foreach (var item in indexedAxisNodePairs)
{
// When more than one input is connected to the same slider, this
// method will decompose the axis corresponding to each input.
var v = GetFirstAxisComponent(item.Value.Item1);
var amount = Math.Round(offset.Dot(v), 3);
if (Math.Abs(amount) > 0.001)
ModifyInputNode(item.Value.Item2, amount);
}
return expectedPosition;
}
示例13: QuatMultiply
static Quat QuatMultiply( Quat q0, Quat q1 )
{
Quat q = new Quat();
Vector V0 = new Vector( q0.qv.x, q0.qv.y, q0.qv.z );
Vector V1 = new Vector( q1.qv.x, q1.qv.y, q1.qv.z );
q.qs = q0.qs * q1.qs - V0.Dot( V1 );
Vector V = q0.qs * V1 + V0 * q1.qs + V0.Cross( V1 );
q.qv.x = V.X;
q.qv.y = V.Y;
q.qv.z = V.Z;
return q;
}
示例14: MolifyReflection
public static float MolifyReflection(float molif_r, ref Vector l, ref Vector rd, ref Normal n, ref Normal nl, float dist)
{
var cos_max = 1f / Sqrt(1f + (molif_r / dist) * (molif_r / dist));// Cone angle
var solid_angle = 2f * M_PI * (1f - cos_max); // Solid angle of the cone
var outv = rd - (n * 2 * n.Dot(ref rd)).ToVec(); // Reflection vector
return l.Dot(ref outv) >= cos_max ? (1f / solid_angle) / l.Dot(ref outv) : 0f; // Mollify
}
示例15: buttonShoot_Click
private void buttonShoot_Click( object sender, EventArgs e )
{
// Clear accumulation
for ( int Y=0; Y < TEXTURE_SIZE; Y++ )
{
for ( int X=0; X < TEXTURE_SIZE; X++ )
{
m_PhotonsAccumulation[X,Y] = 0.0f;
}
}
float LightTheta = (float) Math.PI * floatTrackbarControlTheta.Value / 180.0f;
Vector Light = new Vector( (float) -Math.Sin( LightTheta ), 0.0f, (float) Math.Cos( LightTheta ) );
// float Flux = TEXTURE_SIZE*TEXTURE_SIZE / integerTrackbarControlPhotonsCount.Value;
float Flux = 20000.0f / integerTrackbarControlPhotonsCount.Value;
float PlaneD = (float) Math.Cos( IRIS_START_ANGLE );
float IrisRadius = (float) Math.Sin( IRIS_START_ANGLE );
// Compute bounds for photon generation
float BoundX0 = -IrisRadius;
float BoundX1 = +IrisRadius;
Vector Ortho = new Vector( Light.z, 0.0f, -Light.x ); // Vector tangent to the plane where we can measure projected bounds
float ProjectedBound0 = BoundX0 * Ortho.x + PlaneD * Ortho.z;
float ProjectedBound1 = BoundX1 * Ortho.x + PlaneD * Ortho.z;
ProjectedBound1 = Math.Max( ProjectedBound1, Ortho.z ); // Max with the projected sphere's tangent
ProjectedBound1 *= 1.1f;
// We now have a tight rectangle in projected space [-IrisRadius,ProjectedBound0] [IrisRadius,ProjectedBound1]
// where we can place random photons that will shoot toward the eye's iris.
// We still can miss the sphere though...
// Start shooting
double MaxThetaRandom = Math.Pow( Math.Sin( IRIS_START_ANGLE ), 2.0 );
Vector P = new Vector();
Vector N = new Vector();
Vector Ray = new Vector();
Vector Intersection = new Vector();
float Eta = 1.00029f / 1.34f; // n1 / n2
float fX, fY;
int Px, Py;
for ( int PhotonIndex=0; PhotonIndex < integerTrackbarControlPhotonsCount.Value; PhotonIndex++ )
{
// Wrong as photons are not distributed on the spherical cap
// double Phi = 2.0 * Math.PI * SimpleRNG.GetUniform();
// double Theta = Math.Asin( Math.Sqrt( MaxThetaRandom * SimpleRNG.GetUniform() ) );
//
// N.x = (float) (Math.Sin( Theta ) * Math.Cos( Phi ));
// N.y = (float) (Math.Sin( Theta ) * Math.Sin( Phi ));
// N.z = (float) Math.Cos( Theta );
// if ( N.Dot( Light ) < 0.0f )
// continue; // Opposite side of the spherical cap
// Draw a random position on the light plane and shoot toward the iris
float x = (float) (ProjectedBound0 + SimpleRNG.GetUniform() * (ProjectedBound1 - ProjectedBound0));
float y = (float) (IrisRadius * (2.0 * SimpleRNG.GetUniform() - 1.0));
float SqRadius = x*x + y*y;
if ( SqRadius > 1.0f )
continue; // Photon will hit outside the sphere (should never happen unless iris is as large as the eye itself)
float z = (float) Math.Sqrt( 1.0 - SqRadius );
// Recompute normal at intersection
N.x = x * Ortho.x + z * Light.x;
N.y = y;
N.z = x * Ortho.z + z * Light.z;
if ( N.z < PlaneD )
continue; // We drew a position beneath the iris plane (outside of zone of interest)
// Refract ray through the surface
float c1 = -N.Dot( Light );
float cs2 = 1.0f - Eta * Eta * (1.0f - c1 * c1);
if ( cs2 < 0.0f )
continue; // Total internal reflection
cs2 = Eta * c1 - (float) Math.Sqrt( cs2 );
Ray.x = Eta * Light.x + cs2 * N.x;
Ray.y = Eta * Light.y + cs2 * N.y;
Ray.z = Eta * Light.z + cs2 * N.z;
// Compute intersection with plane
float d = (PlaneD - N.z) / Ray.z;
if ( d < 0.0f )
continue; // ?
Intersection.x = N.x + d * Ray.x;
Intersection.y = N.y + d * Ray.y;
Intersection.z = N.z + d * Ray.z;
fX = 0.5f * (1.0f + Intersection.x / IrisRadius);
fY = 0.5f * (1.0f + Intersection.y / IrisRadius);
//.........这里部分代码省略.........