本文整理汇总了C#中Vector3D.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3D.Normalize方法的具体用法?C# Vector3D.Normalize怎么用?C# Vector3D.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3D
的用法示例。
在下文中一共展示了Vector3D.Normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Normalize
public void Normalize()
{
Vector3D v, n1, n2;
double magnitude;
v = new Vector3D(3.0, 4.0, 0.0);
n1 = v.Normalize();
n2 = v.Normalize(out magnitude);
Assert.AreEqual(1.0, n1.Magnitude, 1e-14);
Assert.AreEqual(1.0, n2.Magnitude, 1e-14);
Assert.AreEqual(5.0, magnitude, 1e-14);
v = new Vector3D(3.0, 0.0, 4.0);
n1 = v.Normalize();
n2 = v.Normalize(out magnitude);
Assert.AreEqual(1.0, n1.Magnitude, 1e-14);
Assert.AreEqual(1.0, n2.Magnitude, 1e-14);
Assert.AreEqual(5.0, magnitude, 1e-14);
v = new Vector3D(0.0, 3.0, 4.0);
n1 = v.Normalize();
n2 = v.Normalize(out magnitude);
Assert.AreEqual(1.0, n1.Magnitude, 1e-14);
Assert.AreEqual(1.0, n2.Magnitude, 1e-14);
Assert.AreEqual(5.0, magnitude, 1e-14);
}
示例2: ReadFromXMLNode
public virtual void ReadFromXMLNode(XmlNode node)
{
try
{
// Deal with model path, must be only one
LoadModelPathNode(node);
// Deal with the start position
XmlNode startPositionNode = node.SelectSingleNode(ModelXMLDefinition.StartPosition);
if (startPositionNode != null)
{
m_ptStartPoint = CPoint3DSerializer.ReadPoint(startPositionNode);
}
// Read the scaleDirection
XmlNode scaleDirectionNode = node.SelectSingleNode(ModelXMLDefinition.SacleDirection);
CPoint3D scaleDirection = CPoint3DSerializer.ReadPoint(scaleDirectionNode);
Vector3D vec = new Vector3D(scaleDirection.X, scaleDirection.Y, scaleDirection.Z);
if (vec.LengthSquared != 0)
{
vec.Normalize();
m_scaleDirection = vec;
}
}
catch (SystemException ex)
{
string errMsg = ex.Message + "\n" + ex.StackTrace;
vtk.vtkOutputWindow.GetInstance().DisplayErrorText(errMsg);
throw;
}
}
示例3: LineD
// IMPORTANT: This struct must be initialized using this constructor, or by filling all four fields. It's because
// some code may need length or distance, and if they aren't calculated, we can have problems.
public LineD(Vector3D from, Vector3D to)
{
From = from;
To = to;
Direction = to - from;
Length = Direction.Normalize();
}
示例4: VolumeSliceArgs
public VolumeSliceArgs(int rows, int columns,
float rowSpacing, float columnSpacing,
Vector3D rowOrientationPatient,
Vector3D columnOrientationPatient,
float sliceThickness, int subsamples,
VolumeInterpolationMode interpolation,
VolumeProjectionMode projection)
{
Platform.CheckPositive(rows, "rows");
Platform.CheckPositive(columns, "columns");
Platform.CheckPositive(rowSpacing, "rowSpacing");
Platform.CheckPositive(columnSpacing, "columnSpacing");
Platform.CheckPositive(sliceThickness, "sliceThickness");
Platform.CheckForNullReference(rowOrientationPatient, "rowOrientationPatient");
Platform.CheckForNullReference(columnOrientationPatient, "columnOrientationPatient");
_rows = rows;
_columns = columns;
_rowSpacing = rowSpacing;
_columnSpacing = columnSpacing;
_rowOrientationPatient = rowOrientationPatient.Normalize();
_columnOrientationPatient = columnOrientationPatient.Normalize();
_sliceThickness = sliceThickness;
_subsamples = subsamples;
_interpolation = interpolation;
_projection = projection;
}
示例5: TestDecompose
public void TestDecompose()
{
Vector3D axis = new Vector3D(.25f, .5f, 0.0f);
axis.Normalize();
Quaternion rot = new Quaternion(axis, TK.MathHelper.Pi);
float x = 50.0f;
float y = 100.0f;
float z = -50.0f;
float scale = 2.0f;
Matrix4x4 m = Matrix4x4.FromScaling(new Vector3D(scale, scale, scale)) * Matrix4x4.FromAngleAxis(TK.MathHelper.Pi, axis) * Matrix4x4.FromTranslation(new Vector3D(x, y, z));
Vector3D scaling1;
Quaternion rotation1;
Vector3D translation1;
Assimp.Unmanaged.AssimpMethods.DecomposeMatrix(ref m, out scaling1, out rotation1, out translation1);
Vector3D scaling2;
Quaternion rotation2;
Vector3D translation2;
m.Decompose(out scaling2, out rotation2, out translation2);
TestHelper.AssertEquals(scaling1.X, scaling1.Y, scaling1.Z, scaling2, "Testing decomposed scaling output");
TestHelper.AssertEquals(rotation1.X, rotation1.Y, rotation1.Z, rotation1.W, rotation2, "Testing decomposed rotation output");
TestHelper.AssertEquals(translation1.X, translation1.Y, translation1.Z, translation2, "Testing decomposed translation output");
m = Matrix4x4.FromAngleAxis(TK.MathHelper.Pi, axis) * Matrix4x4.FromTranslation(new Vector3D(x, y, z));
m.DecomposeNoScaling(out rotation2, out translation2);
TestHelper.AssertEquals(rot.X, rot.Y, rot.Z, rot.W, rotation2, "Testing no scaling decomposed rotation output");
TestHelper.AssertEquals(x, y, z, translation2, "Testing no scaling decomposed translation output");
}
示例6: Offset
/// <summary>
/// Offsets a vector by a hyperbolic distance.
/// </summary>
public static Vector3D Offset( Vector3D v, double hDist )
{
double mag = v.Abs();
mag = DonHatch.h2eNorm( DonHatch.e2hNorm( mag ) + hDist );
v.Normalize();
v *= mag;
return v;
}
示例7: TestNormalize
public void TestNormalize()
{
Vector3D v1 = new Vector3D(2.2F, -6.1F, 7.4F);
Assert.IsTrue(FloatComparer.AreEqual(v1.Magnitude, 9.8392072851F));
Vector3D normalized = v1.Normalize();
Assert.IsTrue(FloatComparer.AreEqual(normalized.Magnitude, 1.0F));
}
示例8: IfcDirection
public IfcDirection(DatabaseIfc db, Vector3D v)
: base(db)
{
UnitVector3D unit = v.Normalize();
mDirectionRatioX = unit.X;
mDirectionRatioY = unit.Y;
mDirectionRatioZ = unit.Z;
}
示例9: MakeFromWV
public static OrthoNormalBasis MakeFromWV(Vector3D w, Vector3D v)
{
OrthoNormalBasis onb = new OrthoNormalBasis();
w.Normalize();
onb.w = w;
onb.u = onb.w ^ v;
onb.u.Normalize();
onb.v = (onb.w ^ onb.u);
return onb;
}
示例10: 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;
}
示例11: NormalizeZeroVector
public void NormalizeZeroVector()
{
Vector3D v = new Vector3D(0.0, 0.0, 0.0);
Vector3D n1 = v.Normalize();
Assert.IsNaN(n1.X);
Assert.IsNaN(n1.Y);
Assert.IsNaN(n1.Z);
Assert.IsTrue(n1.IsUndefined);
double magnitude;
Vector3D n2 = v.Normalize(out magnitude);
Assert.IsNaN(n2.X);
Assert.IsNaN(n2.Y);
Assert.IsNaN(n2.Z);
Assert.IsTrue(n2.IsUndefined);
Assert.AreEqual(0.0, magnitude);
}
示例12: UpdateTransformMatrix
private void UpdateTransformMatrix(Particle particle, BillboardMode mode)
{
lastFacingDirection = inverseView.Translation - particle.Position;
lastCameraUp = inverseView.Up;
AlignBillboardDirection(mode);
lastCameraUp.Normalize();
lastFacingDirection.Normalize();
Vector3D right = Vector3D.Cross(lastCameraUp, lastFacingDirection);
Vector3D up = Vector3D.Cross(lastFacingDirection, right);
lastParticleTransform = Matrix.Identity;
lastParticleTransform.Right = -right;
lastParticleTransform.Up = lastFacingDirection;
lastParticleTransform.Forward = up;
lastParticleTransform *=
Matrix.CreateRotationZYX(lastParticleTransform.Forward.X, lastParticleTransform.Forward.Y,
lastParticleTransform.Forward.Z);
lastParticleTransform.Translation = particle.Position;
}
示例13: MakeFromW
public static OrthoNormalBasis MakeFromW(Vector3D w)
{
OrthoNormalBasis onb = new OrthoNormalBasis();
w.Normalize();
onb.w = w;
if ((Math.Abs(onb.w.X) < Math.Abs(onb.w.Y)) && (Math.Abs(onb.w.X) < Math.Abs(onb.w.Z))) {
onb.v.X = 0;
onb.v.Y = onb.w.Z;
onb.v.Z = -onb.w.Y;
} else if (Math.Abs(onb.w.Y) < Math.Abs(onb.w.Z)) {
onb.v.X = onb.w.Z;
onb.v.Y = 0;
onb.v.Z = -onb.w.X;
} else {
onb.v.X = onb.w.Y;
onb.v.Y = -onb.w.X;
onb.v.Z = 0;
}
onb.v.Normalize();
onb.u = onb.v ^ onb.w;
return onb;
}
示例14: DetermineVelocity
public void DetermineVelocity(ZACommons commons, EventDriver eventDriver)
{
if (!Enabled) return;
var shipControl = (ShipControlCommons)commons;
var velocity = (shipControl.ReferencePoint - LastPosition) /
((double)SampleDelay / 60.0);
TargetVector = -velocity;
var speed = TargetVector.Normalize();
if (speed > 0.1)
{
eventDriver.Schedule(FramesPerRun, Reorient);
}
else
{
var gyroControl = shipControl.GyroControl;
gyroControl.Reset();
gyroControl.EnableOverride(false);
shipControl.ThrustControl.Enable(true);
}
}
示例15: Render
public static Bitmap Render(Light_ lgt)
{
light = lgt;
Vector3D direction = new Vector3D();
Color color;
for (int i = 0; i < xResolution; i++)
{
for (int j = 0; j < yResolution; j++)
{
direction = vectorU * (i / (float)(xResolution - 1)) + vectorV * (j / (float)(yResolution - 1));
direction += topLeft;
direction -= observer;
direction.Normalize();
color = CalculateColor(observer, direction, 0);
image.SetPixel(i, j, color);
}
}
return image;
}