本文整理汇总了C#中VectorD.Unit方法的典型用法代码示例。如果您正苦于以下问题:C# VectorD.Unit方法的具体用法?C# VectorD.Unit怎么用?C# VectorD.Unit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VectorD
的用法示例。
在下文中一共展示了VectorD.Unit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrincipalOrientationCenter
VectorD PrincipalOrientationCenter(out PointD center)
// The principle orientation is one of the eigenvectors of the covariance matrix
{
double meanX, meanY;
double[,] covariance = CovarianceMatrix(out meanX, out meanY);
center = new PointD(meanX, meanY);
//
double a = covariance[0,0], b = covariance[0,1];
double c = covariance[1,0], d = covariance[1,1];
//
double r = Math.Sqrt(a*a + 4*b*c - 2*a*d + d*d);
double n = (a - d + r); Debug.Assert(n >= 0);
double x = n / (2 * c);
//
if (!x.IsFinite())
{
// Y does not vary with X: all X's look the same so far as Y is concerned
//
double width = this.Vertices.Max(v => v.Location.X) - this.Vertices.Min(v => v.Location.X);
double height = this.Vertices.Max(v => v.Location.Y) - this.Vertices.Min(v => v.Location.Y);
if (width > height)
return new VectorD(1, 0);
else
return new VectorD(0, 1);
}
else
{
VectorD eigenVector = new VectorD(x, 1) * Math.Sign(c);
return eigenVector.Unit();
}
}