本文整理汇总了C#中Vector3d.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3d.Equals方法的具体用法?C# Vector3d.Equals怎么用?C# Vector3d.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3d
的用法示例。
在下文中一共展示了Vector3d.Equals方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AngleInRadian
/// <summary>
/// Angle between 2 Vector in radian
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static double AngleInRadian(this Vector3d a, Vector3d b)
{
if (a.Equals(Vector3d.Zero) || b.Equals(Vector3d.Zero))
return (double)(2 * Math.PI);
Vector3d v = Vector3d.Cross(a, b);
double d1 = v.Length;//v.Norm();
double d2 = Vector3d.Dot(a, b);
double angle = Math.Atan2(d1, d2);
return (double)angle;
}
示例2: ApplyDesiredVelocity
public Vector3d ApplyDesiredVelocity(Vector3d desiredVelocity, double weightMultiplier)
{
if (desiredVelocity.Equals(Vector3d.Zero))
{
return Vector3d.Zero;
}
// Reynold's steering formula: steer = desired - velocity
desiredVelocity = desiredVelocity - Velocity;
// Steering ability can be controlled by limiting the magnitude of the steering force.
desiredVelocity = Util.Vector.Limit(desiredVelocity, MaxForce);
desiredVelocity = desiredVelocity * weightMultiplier;
SteerAcceleration += desiredVelocity;
return desiredVelocity;
}
示例3: ProjectOnLine
/// <summary>
/// Returns the projection of a point on the line defined with two other points.
/// When the projection is out of the segment, then the closest extremity is returned.
/// </summary>
/// <exception cref="ArgumentNullException">None of the arguments can be null.</exception>
/// <exception cref="ArgumentException">P1 and P2 must be different.</exception>
/// <param name="Pt">Point to project.</param>
/// <param name="P1">First point of the line.</param>
/// <param name="P2">Second point of the line.</param>
/// <returns>The projected point if it is on the segment / The closest extremity otherwise.</returns>
public static Vector3d ProjectOnLine(Vector3d Pt, Vector3d P1, Vector3d P2)
{
if (Pt == null || P1 == null || P2 == null) throw new ArgumentNullException("None of the arguments can be null.");
if (P1.Equals(P2)) throw new ArgumentException("P1 and P2 must be different.");
Vector3d VLine = MakeDiff(P1, P2);
Vector3d V1Pt = MakeDiff(P1, Pt);
Vector3d Translation = VLine * VectOR(VLine, V1Pt) / SquareNorm(VLine);
Vector3d Projection = P1 + Translation;
Vector3d V1Pjt = MakeDiff(P1, Projection);
double D1 = VectOR(V1Pjt, VLine);
if (D1 < 0) return P1;
Vector3d V2Pjt = MakeDiff(P2, Projection);
double D2 = VectOR(V2Pjt, VLine);
if (D2 > 0) return P2;
return Projection;
}
示例4: ColorReflection
public double[] ColorReflection( IMaterial material, Vector3d normal, Vector3d input, Vector3d output, ReflectionComponent comp )
{
if ( !(material is PhongMaterial) ) return null;
PhongMaterial mat = (PhongMaterial)material;
int bands = mat.Color.Length;
double[] result = new double[ bands ];
bool viewOut = Vector3d.Dot( output, normal ) > 0.0;
double coef;
if ( input.Equals( Vector3d.Zero ) ) // ambient term only..
{
// dim ambient light if viewer is inside
coef = viewOut ? mat.Ka : (mat.Ka * mat.Kt);
for ( int i = 0; i < bands; i++ )
result[ i ] = coef * mat.Color[ i ];
return result;
}
// directional light source:
input.Normalize();
double cosAlpha = Vector3d.Dot( input, normal );
bool lightOut = cosAlpha > 0.0;
double ks = mat.Ks;
double kd = mat.Kd;
double kt = mat.Kt;
Vector3d r = Vector3d.Zero;
coef = 1.0;
if ( viewOut == lightOut ) // viewer and source are on the same side..
{
if ( (comp & ReflectionComponent.SPECULAR_REFLECTION) != 0 )
{
double cos2 = cosAlpha + cosAlpha;
r = normal * cos2 - input;
if ( !lightOut && // total reflection check
-cosAlpha <= mat.cosTotal )
if ( (ks += kt) + kd > 1.0 )
ks = 1.0 - kd;
}
}
else // opposite sides => use specular refraction
{
if ( (comp & ReflectionComponent.SPECULAR_REFRACTION) != 0 )
r = Geometry.SpecularRefraction( normal, mat.n, input );
coef = kt;
}
double diffuse = (comp & ReflectionComponent.DIFFUSE) == 0 ? 0.0 : coef * kd * Math.Abs( cosAlpha );
double specular = 0.0;
if ( r != Vector3d.Zero )
{
double cosBeta = Vector3d.Dot( r, output );
if ( cosBeta > 0.0 )
specular = coef * ks * Arith.Pow( cosBeta, mat.H );
}
for ( int i = 0; i < bands; i++ )
result[i] = diffuse * mat.Color[i] + specular;
return result;
}