当前位置: 首页>>代码示例>>C#>>正文


C# LineSegment.Vector方法代码示例

本文整理汇总了C#中LineSegment.Vector方法的典型用法代码示例。如果您正苦于以下问题:C# LineSegment.Vector方法的具体用法?C# LineSegment.Vector怎么用?C# LineSegment.Vector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LineSegment的用法示例。


在下文中一共展示了LineSegment.Vector方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProjectOnto

		public static Point ProjectOnto(this Point p, LineSegment seg, LineType type, out int? end)
		{
			end = 0;
			Vector v = seg.Vector();
			Vector w = p.Sub(seg.A);
			T c1 = w.Dot(v); // c1 == |w|*|v|*cos(angle between them)
			if (c1 <= 0) { // angle between line segment and (p-seg.A) is negative (-180..0)?
				if (v.X == 0 && v.Y == 0) {
					// seg.A == seg.B
					end = null;
					return seg.A;
				} else if (c1 < 0)
					end = -1;
				if (type != LineType.Infinite)
					return seg.A;
			}
			T c2 = v.Quadrance(); // == |v|*|v|
			if (c1 >= c2) { // quadrance from seg.A to projected point >= quadrance of seg
				if (c1 > c2)
					end = 1;
				if (type == LineType.Segment)
					return seg.B;
			}
			if (c2 == 0) {
				// seg.A and seg.B are infitessimally close together; c2 was truncated to zero
				end = null;
				return seg.A;
			}

			T frac = c1 / c2;                    // == |w|/|v|*cos(angle)
			Point projected = seg.A.Add(v.Mul(frac)); // == p0 + v/|v|*|w|*cos(angle)
			return projected;
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:33,代码来源:LineMathTT.cs

示例2: LLShape

		public LLMarkerRotated LLShape(DrawStyle style, ref LineSegment<Coord> toArrow)
		{
			Coord frac = Width * Scale / toArrow.Length();
			var markerPoint = toArrow.PointAlong(1 - frac * 0.5f);
			toArrow = toArrow.A.To(toArrow.PointAlong(1 - Math.Min(frac, 1)));
			return new LLMarkerRotated(style, markerPoint, Scale, Geometry, (Coord)toArrow.Vector().AngleDeg());
		}
开发者ID:Shaykh,项目名称:Loyc,代码行数:7,代码来源:LineOrArrow.cs

示例3: ComputeIntersection

		/// <summary>Computes the location that lines, rays or line segments 
		/// intersect, expressed as a fraction of the distance along each 
		/// LineSegment.</summary>
		/// <param name="P">First line segment</param>
		/// <param name="pType">Type of line P (Segment, Ray, Infinite)</param>
		/// <param name="pFrac">Fraction along P of the intersection point. If this
		/// method returns false, pFrac is still computed. If the hypothetical
		/// intersection point of the infinite extension of P and Q is beyond the 
		/// P.A side of the line, pFrac is set to an appropriate negative value if 
		/// pType is Infinite and 0 otherwise. If the hypothetical intersection
		/// is on the P.B side of the line, pFrac is set to 1 if pType is Segment
		/// and a value above 1 otherwise.</param>
		/// <param name="Q">Second line segment</param>
		/// <param name="qType">Type of line Q (Segment, Ray, Infinite)</param>
		/// <param name="qFrac">Fraction along Q of the intersection point. If this
		/// method returns false, qFrac may be <c>NaN</c> if the analysis of line
		/// P already determined that pFrac is beyond the range of line P. In other 
		/// words, if Q is assumed to be an infinite line and P still does not 
		/// intersect with Q, qFrac is set to NaN because the method aborts 
		/// analysis to avoid wasting CPU time. On the other hand, if this method 
		/// determines that P might intersect with Q, but a full analysis shows 
		/// that it does not, the method returns false and sets qFrac to a real 
		/// number. qFrac is set to 0 if the intersection point of the infinite 
		/// extension of Q is on the Q.A side of the line, and 1 if the 
		/// intersection point is on the Q.B side of the line.</param>
		/// <returns>True if the lines intersect, false otherwise.</returns>
		/// <remarks>
		/// This method does not do a bounding-box check. If you are doing 
		/// calculations with line segments and you expect the majority of your
		/// intersection calculations to return false, you may save time by 
		/// testing whether the bounding boxes of the lines overlap before calling 
		/// this method.
		/// <para/>
		/// If the input segments contain NaNs, the result is false and pFrac/qFrac
		/// will be NaN.
		/// <para/>
		/// If the either of the line segments are degenerate (single points), 
		/// overlap can still be detected and the LineType of the degenerate line
		/// has no effect; the degenerate line is always treated as a point.
		/// If both lines are points, the method will return true iff they are the
		/// same point, and if true is returned, pFrac will be 0.5f
		/// <para/>
		/// The output fractions pFrac and qFrac will be infinite if the magnitude 
		/// of the result overflows.
		/// <para/>
		/// If the two line segments are parallel but do not overlap, this method
		/// returns false; pFrac and qFrac are both set to NaN. If the two lines 
		/// are parallel and overlap, a region of overlap is detected and pFrac
		/// and qFrac refer to the center of this region of overlap. If, in this
		/// case, P and/or Q are rays or infinite lines, this method behaves as
		/// though P and/or Q are extended to cover each other. For instance, 
		/// suppose that P and Q are lines on the X axis, P.A.X=0, P.B.X=6, 
		/// Q.A.X=10, Q.B.X=16:
		/// <pre>
		///        P.A---------------P.B         Q.B---------------------Q.A
		/// -2  -1  0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17
		/// </pre>
		/// If P and Q are both line segments, there is no overlap and this method 
		/// will return false. However, if Q is a Ray or an infinite line, it 
		/// extends toward negative infinity and the minimum overlap between the 
		/// lines is 0..6. In this case, the region of overlap is considered to be 
		/// 0..6 if P is a line segment, and 0..16 if P is a ray or an infinite 
		/// line. If P is a line segment, the midpoint is 3, and pFrac will be set
		/// to 0.5, halfway along the line, while qFrac will be 2.333. If P is a 
		/// ray or an infinite line, the midpoint is 8, pFrac will be 1.333, and
		/// qFrac will be 1.333.
		/// </remarks>
		public static bool ComputeIntersection(this LineSegment P, LineType pType, out T pFrac, LineSegment Q, LineType qType, out T qFrac)
		{
			pFrac = T.NaN;
			qFrac = T.NaN;

			Vector dP = P.Vector();
			Vector dQ = Q.Vector();

			Vector QA_PA = P.A.Sub(Q.A);
			T denom = (-dQ.X * dP.Y + dP.X * dQ.Y);
			bool negDenom = false;
			if (denom == 0)
				goto parallel;
			T pNumer = (dQ.X * (QA_PA.Y) - dQ.Y * (QA_PA.X));
			if (denom < 0) {
				negDenom = true;
				denom = -denom;
				pNumer = -pNumer; 
			}
			if (pType != LineType.Infinite) {
				if (pNumer < 0) {
					pFrac = 0;
					return false;
				}
				if (pNumer > denom && pType == LineType.Segment) {
					pFrac = 1;
					return false;
				}
			}
			pFrac = pNumer / denom;
			if (T.IsNaN(pFrac))
				return false;
			
//.........这里部分代码省略.........
开发者ID:qwertie,项目名称:ecsharp,代码行数:101,代码来源:LineMathTT.cs


注:本文中的LineSegment.Vector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。