本文整理汇总了C#中Vector3D.Dot方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3D.Dot方法的具体用法?C# Vector3D.Dot怎么用?C# Vector3D.Dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3D
的用法示例。
在下文中一共展示了Vector3D.Dot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryRayPlane
public static bool TryRayPlane(
Vector3D rayOrigin,
Vector3D rayDirection,
Vector3D planeNormal,
double planeD,
out Vector3D intersectionPoint)
{
double denominator = planeNormal.Dot(rayDirection);
if (Math.Abs(denominator) < 0.00000000000000000001)
{
//
// Ray is parallel to plane. The ray may be in the polygon's plane.
//
intersectionPoint = Vector3D.Zero;
return false;
}
double t = (-planeD - planeNormal.Dot(rayOrigin)) / denominator;
if (t < 0)
{
intersectionPoint = Vector3D.Zero;
return false;
}
intersectionPoint = rayOrigin + (t * rayDirection);
return true;
}
示例2: SubtendedAngle
/// <summary>
/// Calculates the angle subtended by two line segments that meet at a vertex.
/// </summary>
/// <param name="start">The end of one of the line segments.</param>
/// <param name="vertex">The vertex of the angle formed by the two line segments.</param>
/// <param name="end">The end of the other line segment.</param>
/// <returns>The angle subtended by the two line segments in degrees.</returns>
public static double SubtendedAngle(PointF start, PointF vertex, PointF end)
{
Vector3D vertexPositionVector = new Vector3D(vertex.X, vertex.Y, 0);
Vector3D a = new Vector3D(start.X, start.Y, 0) - vertexPositionVector;
Vector3D b = new Vector3D(end.X, end.Y, 0) - vertexPositionVector;
float dotProduct = a.Dot(b);
Vector3D crossProduct = a.Cross(b);
float magA = a.Magnitude;
float magB = b.Magnitude;
if (FloatComparer.AreEqual(magA, 0F) || FloatComparer.AreEqual(magB, 0F))
return 0;
double cosTheta = dotProduct/magA/magB;
// Make sure cosTheta is within bounds so we don't
// get any errors when we take the acos.
if (cosTheta > 1.0f)
cosTheta = 1.0f;
if (cosTheta < -1.0f)
cosTheta = -1.0f;
double theta = Math.Acos(cosTheta)*(crossProduct.Z == 0 ? 1 : -Math.Sign(crossProduct.Z));
double thetaInDegrees = theta/Math.PI*180;
return thetaInDegrees;
}
示例3: GnomonicToStereo
public static Vector3D GnomonicToStereo( Vector3D g )
{
g /= m_gScale;
double dot = g.Dot( g ); // X^2 + Y^2
double z = -1 / Math.Sqrt( dot + 1 );
return g*z / (z - 1);
}
示例4: KleinToPoincare
public static Vector3D KleinToPoincare( Vector3D k )
{
double dot = k.Dot( k );
if( dot > 1 ) // This avoids some NaN problems I saw.
dot = 1;
double mag = (1 - Math.Sqrt( 1 - dot )) / dot;
return k * mag;
}
示例5: PlaneToSphere
public static Vector3D PlaneToSphere( Vector3D planePoint )
{
planePoint.Z = 0;
double dot = planePoint.Dot( planePoint ); // X^2 + Y^2
return new Vector3D(
2 * planePoint.X / ( dot + 1 ),
2 * planePoint.Y / ( dot + 1 ),
( dot - 1 ) / ( dot + 1 ) );
}
示例6: Orthogonalize
public static Matrix3D Orthogonalize(Vector3D u, Vector3D v)
{
Vector3D a = u.Normalize();
Vector3D temp = v - (v.Dot(a)) * a;
Vector3D b = temp.Normalize();
Vector3D c = a.Cross(b).Normalize();
Matrix3D e = new Matrix3D(a, b, c);
return e;
}
示例7: R3toS3
public static Vector3D R3toS3( Vector3D p )
{
if( Infinity.IsInfinite( p ) )
return new Vector3D( 0, 0, 0, 1 );
p.W = 0;
double dot = p.Dot( p ); // X^2 + Y^2 + Z^2
return new Vector3D(
2 * p.X / ( dot + 1 ),
2 * p.Y / ( dot + 1 ),
2 * p.Z / ( dot + 1 ),
( dot - 1 ) / ( dot + 1 ) );
}
示例8: _Seek
private GyroControl _Seek(ShipControlCommons shipControl,
Vector3D targetVector, Vector3D? targetUp,
out double yawError, out double pitchError,
out double rollError)
{
Vector3D referenceForward;
Vector3D referenceLeft;
Vector3D referenceUp;
GyroControl gyroControl;
// See if local orientation is the same as the ship
if (shipControl.ShipUp == ShipUp && shipControl.ShipForward == ShipForward)
{
// Use same reference vectors and GyroControl
referenceForward = shipControl.ReferenceForward;
referenceLeft = shipControl.ReferenceLeft;
referenceUp = shipControl.ReferenceUp;
gyroControl = shipControl.GyroControl;
}
else
{
referenceForward = GetReferenceVector(shipControl, ShipForward);
referenceLeft = GetReferenceVector(shipControl, ShipLeft);
referenceUp = GetReferenceVector(shipControl, ShipUp);
// Need our own GyroControl instance in this case
gyroControl = new GyroControl();
gyroControl.Init(shipControl.Blocks,
shipUp: ShipUp,
shipForward: ShipForward);
}
// Determine projection of targetVector onto our reference unit vectors
var dotZ = targetVector.Dot(referenceForward);
var dotX = targetVector.Dot(referenceLeft);
var dotY = targetVector.Dot(referenceUp);
var projZ = dotZ * referenceForward;
var projX = dotX * referenceLeft;
var projY = dotY * referenceUp;
// Determine yaw/pitch error by calculating angle between our forward
// vector and targetVector
var z = projZ.Length() * Math.Sign(dotZ);
var x = projX.Length() * Math.Sign(dotX);
var y = projY.Length() * Math.Sign(-dotY); // NB inverted
yawError = Math.Atan2(x, z);
pitchError = Math.Atan2(y, z);
var gyroYaw = yawPID.Compute(yawError);
var gyroPitch = pitchPID.Compute(pitchError);
gyroControl.SetAxisVelocityFraction(GyroControl.Yaw, (float)gyroYaw);
gyroControl.SetAxisVelocityFraction(GyroControl.Pitch, (float)gyroPitch);
if (targetUp != null)
{
// Also adjust roll
dotX = ((Vector3D)targetUp).Dot(referenceLeft);
dotY = ((Vector3D)targetUp).Dot(referenceUp);
projX = dotX * referenceLeft;
projY = dotY * referenceUp;
x = projX.Length() * Math.Sign(-dotX);
y = projY.Length() * Math.Sign(dotY);
rollError = Math.Atan2(x, y);
var gyroRoll = rollPID.Compute(rollError);
gyroControl.SetAxisVelocityFraction(GyroControl.Roll, (float)gyroRoll);
}
else
{
rollError = default(double);
}
return gyroControl;
}
示例9: ComputeAngle
private static double ComputeAngle(ref Vector3D v1, ref Vector3D v2)
{
double cosa = v1.Dot(v2);
double angle = Math.Acos(MathUtil.ClampWithRange(cosa, -1, 1));
return angle; ;
}
示例10: GetTextBoxAdjustmentParameters
private bool GetTextBoxAdjustmentParameters(out PointF startPoint, out PointF endPoint, out float lengthOfLineThroughTextBox)
{
startPoint = _topParent.Points[0];
endPoint = _topParent.Points[1];
lengthOfLineThroughTextBox = 0;
Vector3D lineDirection = new Vector3D(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y, 0F);
if (Vector3D.AreEqual(lineDirection, Vector3D.Null))
return false;
Vector3D lineUnit = lineDirection.Normalize();
Vector3D xUnit = new Vector3D(1F, 0, 0);
Vector3D yUnit = new Vector3D(0, 1F, 0);
float cosThetaX = Math.Abs(xUnit.Dot(lineUnit));
float cosThetaY = Math.Abs(yUnit.Dot(lineUnit));
float textWidth = _textGraphic.BoundingBox.Width;
float textHeight = _textGraphic.BoundingBox.Height;
if (cosThetaX >= cosThetaY)
{
// the distance along the line to where we want the outside right edge of the text to be.
lengthOfLineThroughTextBox = cosThetaX*textWidth;
if (lineDirection.X < 0)
{
startPoint = _topParent.Points[1];
endPoint = _topParent.Points[0];
}
}
else
{
// the distance along the line to where we want the outside bottom edge of the text to be.
lengthOfLineThroughTextBox = cosThetaY*textHeight;
if (lineDirection.Y < 0)
{
startPoint = _topParent.Points[1];
endPoint = _topParent.Points[0];
}
}
return true;
}
示例11: ComputeRotationRodrigues
public static Matrix3D ComputeRotationRodrigues(Vector3D first, Vector3D second, int step)
{
Vector3D cross = first.Cross(second);
double sin = cross.Length();
double cos = first.Dot(second);
//if (cos > 0.99)
//{
// return Matrix3D.IdentityMatrix();
//}
double angle = Math.Acos(cos);
cos = Math.Cos(angle / step);
sin = Math.Sin(angle / step);
cross = cross.Normalize();
double x = cross.x;
double y = cross.y;
double z = cross.z;
Matrix3D result = Matrix3D.IdentityMatrix();
//result[0, 0] = cos+(1-cos)*x*x;
//result[0, 1] = x * y*(1 - cos) - z * sin;
//result[0, 2] = y* sin+x*z*(1-cos);
//result[1, 0] = z * sin + x * y * (1 - cos);
//result[1, 1] = cos + y * y * (1 - cos);
//result[1, 2] = -x * sin + y * z * (1 - cos);
//result[2, 0] = -y * sin + x * z * (1 - cos);
//result[2, 1] = x * sin + y * z * (1 - cos);
//result[2, 2] =cos + z* z * (1 - cos);
//result[0, 0] = cos*(y*y+z*z) + x * x;
//result[0, 1] = x * y * (1 - cos) - z * sin;
//result[0, 2] = y * sin + x * z * (1 - cos);
//result[1, 0] = z * sin + x * y * (1 - cos);
//result[1, 1] = cos*(x*x+z*z) + y * y ;
//result[1, 2] = -x * sin + y * z * (1 - cos);
//result[2, 0] = -y * sin + x * z * (1 - cos);
//result[2, 1] = x * sin + y * z * (1 - cos);
//result[2, 2] = cos*(x*x+y*y) + z * z ;
result[0, 0] = cos * (1 - x * x) + x * x;
result[0, 1] = x * y * (1 - cos) - z * sin;
result[0, 2] = y * sin + x * z * (1 - cos);
result[1, 0] = z * sin + x * y * (1 - cos);
result[1, 1] = cos * (1 - y * y) + y * y;
result[1, 2] = -x * sin + y * z * (1 - cos);
result[2, 0] = -y * sin + x * z * (1 - cos);
result[2, 1] = x * sin + y * z * (1 - cos);
result[2, 2] = cos * (1 - z * z) + z * z;
// result = result.Transpose();
return result;
}
示例12: FromPoints
public static PlaneD FromPoints(Vector3D p1, Vector3D p2, Vector3D p3)
{
Vector3D Normal = (p2 - p1).Cross(p3 - p1);
Normal.Normalize();
return new PlaneD(Normal, -p1.Dot(Normal));
}
示例13: PoincareToKlein
public static Vector3D PoincareToKlein( Vector3D p )
{
double mag = 2 / (1 + p.Dot( p ));
return p * mag;
}
示例14: CalcRotateMatrixFromOrthogonalBasis
private static Matrix CalcRotateMatrixFromOrthogonalBasis(Vector3D xAxis, Vector3D yAxis, Vector3D zAxis)
{
const float zeroTolerance = 1e-4f;
Platform.CheckForNullReference(xAxis, "xAxis");
Platform.CheckForNullReference(yAxis, "yAxis");
Platform.CheckForNullReference(zAxis, "zAxis");
Platform.CheckFalse(xAxis.IsNull || yAxis.IsNull || zAxis.IsNull, "Input must be an orthogonal set of basis vectors (i.e. non-trivial vectors).");
Platform.CheckTrue(FloatComparer.AreEqual(xAxis.Dot(yAxis), 0, zeroTolerance)
&& FloatComparer.AreEqual(xAxis.Dot(zAxis), 0, zeroTolerance)
&& FloatComparer.AreEqual(yAxis.Dot(zAxis), 0, zeroTolerance), "Input must be an orthogonal set of basis vectors (i.e. mutually perpendicular).");
xAxis = xAxis.Normalize();
yAxis = yAxis.Normalize();
zAxis = zAxis.Normalize();
//TODO (CR Sept 2010): is this a rotation matrix, or the definition of a coordinate system?
var basis = new Matrix(4, 4);
basis.SetRow(0, xAxis.X, xAxis.Y, xAxis.Z, 0);
basis.SetRow(1, yAxis.X, yAxis.Y, yAxis.Z, 0);
basis.SetRow(2, zAxis.X, zAxis.Y, zAxis.Z, 0);
basis.SetRow(3, 0, 0, 0, 1);
return basis;
}
示例15: Shade
public virtual Color Shade(Vector3D p, Vector3D n, Vector3D v, ArrayList lights,
ArrayList objects, Color bgnd)
{
IEnumerator lightSources = lights.GetEnumerator();
float r = 0;
float g = 0;
float b = 0;
while (lightSources.MoveNext())
{
Light light = (Light)lightSources.Current;
if (light.lightType == Light.AMBIENT)
{
r += ka * ir * light.ir;
g += ka * ig * light.ig;
b += ka * ib * light.ib;
}
else
{
Vector3D l;
if (light.lightType == Light.POINT)
{
l = new Vector3D(light.lvec.x - p.x, light.lvec.y - p.y, light.lvec.z - p.z);
l.Normalize();
}
else
{
l = new Vector3D(-light.lvec.x, -light.lvec.y, -light.lvec.z);
}
// Check if the surface point is in shadow
Vector3D poffset = new Vector3D(p.x + TINY * l.x, p.y + TINY * l.y, p.z + TINY *
l.z);
Ray shadowRay = new Ray(poffset, l);
if (shadowRay.Trace(objects))
{
break;
}
float lambert = Vector3D.Dot(n, l);
if (lambert > 0)
{
if (kd > 0)
{
float diffuse = kd * lambert;
r += diffuse * ir * light.ir;
g += diffuse * ig * light.ig;
b += diffuse * ib * light.ib;
}
if (ks > 0)
{
lambert *= 2;
float spec = v.Dot(lambert * n.x - l.x, lambert * n.y - l.y, lambert * n.z - l.z);
if (spec > 0)
{
spec = ks * ((float)Math.Pow((double)spec, (double)ns));
r += spec * light.ir;
g += spec * light.ig;
b += spec * light.ib;
}
}
}
}
}
// Compute illumination due to reflection
if (kr > 0)
{
float t = v.Dot(n);
if (t > 0)
{
t *= 2;
Vector3D reflect = new Vector3D(t * n.x - v.x, t * n.y - v.y, t * n.z - v.z);
Vector3D poffset = new Vector3D(p.x + TINY * reflect.x, p.y + TINY * reflect.y, p
.z + TINY * reflect.z);
Ray reflectedRay = new Ray(poffset, reflect);
if (reflectedRay.Trace(objects))
{
Color rcolor = reflectedRay.Shade(lights, objects, bgnd);
r += kr * rcolor.GetRed();
g += kr * rcolor.GetGreen();
b += kr * rcolor.GetBlue();
}
else
{
r += kr * bgnd.GetRed();
g += kr * bgnd.GetGreen();
b += kr * bgnd.GetBlue();
}
}
}
// Add code for refraction here
r = (r > 1f) ? 1f : r;
g = (g > 1f) ? 1f : g;
b = (b > 1f) ? 1f : b;
return new Color(r, g, b);
}