本文整理汇总了C#中System.Vector2.Distance7方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2.Distance7方法的具体用法?C# Vector2.Distance7怎么用?C# Vector2.Distance7使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Vector2
的用法示例。
在下文中一共展示了Vector2.Distance7方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CircleCircleIntersection
/// <summary>
/// Returns the two intersection points between two circles.
/// </summary>
public static Vector2[] CircleCircleIntersection(Vector2 center1, Vector2 center2, float radius1, float radius2)
{
var D = center1.Distance7(center2);
//The Circles dont intersect:
if (D > radius1 + radius2 || (D <= Math.Abs(radius1 - radius2)))
{
return new Vector2[] { };
}
var A = (radius1 * radius1 - radius2 * radius2 + D * D) / (2 * D);
var H = (float)Math.Sqrt(radius1 * radius1 - A * A);
var Direction = (center2 - center1).Normalized2();
var PA = center1 + A * Direction;
var S1 = PA + H * Direction.Perpendicular2();
var S2 = PA - H * Direction.Perpendicular2();
return new[] { S1, S2 };
}
示例2: GetCandidates
internal static Vector2[] GetCandidates(Vector2 from, Vector2 to, float radius, float range)
{
var middlePoint = (from + to) / 2;
var intersections = Geometry2.CircleCircleIntersection(
from, middlePoint, radius, from.Distance7(middlePoint));
if (intersections.Length > 1)
{
var c1 = intersections[0];
var c2 = intersections[1];
c1 = from + range * (to - c1).Normalized2();
c2 = from + range * (to - c2).Normalized2();
return new[] { c1, c2 };
}
return new Vector2[] { };
}