本文整理汇总了C#中Segment.Direct方法的典型用法代码示例。如果您正苦于以下问题:C# Segment.Direct方法的具体用法?C# Segment.Direct怎么用?C# Segment.Direct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Segment
的用法示例。
在下文中一共展示了Segment.Direct方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InterectSegment
/// </remarks>
bool InterectSegment(Segment s1,Segment s2,out Vector2 interectPot)
{
Vector3 crossResult = Vector3.Cross(s1.Direct(), s2.Direct());
if (crossResult.z == 0F)
{
interectPot = Vector2.zero;
return false;
}
float x1 = s1.P1.x, x2 = s1.P2.x, x3 = s2.P1.x, x4 = s2.P2.x;
float y1 = s1.P1.y, y2 = s1.P2.y, y3 = s2.P1.y, y4 = s2.P2.y;
interectPot.x = ((x1 - x2) * (x3 * y4 - x4 * y3) - (x3 - x4) * (x1 * y2 - x2 * y1)) / ((x3 - x4) * (y1 - y2) - (x1 - x2) * (y3 - y4));
interectPot.y = ((y1 - y2) * (x3 * y4 - x4 * y3) - (x1 * y2 - x2 * y1) * (y3 - y4)) / ((y1 - y2) * (x3 - x4) - (x1 - x2) * (y3 - y4));
if ((interectPot.x - s1.P1.x) * (interectPot.x - s1.P2.x) <= 0
&& (interectPot.y - s1.P1.y) * (interectPot.y - s1.P2.y) <= 0
&& (interectPot.x - s2.P1.x) * (interectPot.x - s2.P2.x) <= 0
&& (interectPot.y - s2.P1.y) * (interectPot.y - s2.P2.y) <= 0
)
{
return true;
}
return false;
}