/*protected void _CalculateEdges() * { * // Assign edges * mEdges = new SimpleLine[4]; * * // 0 > > 3 * // v ^ * // v ^ * // 1 > > 2 * * // Left - top-left to bottom-left * mEdges[0] = new SimpleLine(mPolygon.Left, mPolygon.Top, mPolygon.Left, mPolygon.Bottom); * // Bottom - bottom-left to bottom-right * mEdges[1] = new SimpleLine(mPolygon.Left, mPolygon.Bottom, mPolygon.Right, mPolygon.Bottom); * // Right - bottom-right to top-right * mEdges[2] = new SimpleLine(mPolygon.Right, mPolygon.Bottom, mPolygon.Right, mPolygon.Top); * // Top - top-left to top-right * mEdges[3] = new SimpleLine(mPolygon.Left, mPolygon.Top, mPolygon.Right, mPolygon.Top); * }*/ protected void _CalculateEdges() { // Assign edges // v1 old: // 0 > > 3 // v v // v v // 1 > > 2 // v2 current - counter-clocwise order of points: // 0 < < 3 // v ^ // v ^ // 1 > > 2 // Left - top-left to bottom-left _EdgeLeft = new SimpleLine(Polygon.Left, Polygon.Top, Polygon.Left, Polygon.Bottom); // Bottom - bottom-left to bottom-right _EdgeBottom = new SimpleLine(Polygon.Left, Polygon.Bottom, Polygon.Right, Polygon.Bottom); // Right - bottom-right to top-right _EdgeRight = new SimpleLine(Polygon.Right, Polygon.Bottom, Polygon.Right, Polygon.Top); // Top - top-right to top-left _EdgeTop = new SimpleLine(Polygon.Right, Polygon.Top, Polygon.Left, Polygon.Top); /*Debug.ShowLine(_EdgeRight, Color.Green); * Debug.ShowLine(_EdgeLeft, Color.DarkGreen); * Debug.ShowLine(_EdgeTop, Color.Cyan); * Debug.ShowLine(_EdgeBottom, Color.DarkCyan);*/ }
public static void ShowLine(SimpleLine line, Color color) { var visLine = ShapeManager.AddLine(); visLine.SetFromAbsoluteEndpoints(new Point3D(line.Start.X, line.Start.Y), new Point3D(line.End.X, line.End.Y)); visLine.Color = color; //visLine.Visible = true; }
private static Point _LineCenter(SimpleLine line) { //x=(x1+x2) / 2 //y=(y1+y22) / 2 return(new Point( (line.Start.X + line.End.X) / 2, (line.Start.Y + line.End.Y) / 2 )); }
/// <summary> /// Creates a new Link. /// </summary> /// <param name="nodeLinkingTo">The node to link to.</param> /// <param name="cost">The cost to travel the link.</param> /// <param name="portal">Portal line facing from parent PortalNode to destination node (for Channel construction).</param> public static TLink Create(TNode nodeLinkingTo, float cost, SimpleLine portal) { return(new TLink { mNodeLinkingTo = nodeLinkingTo, mCost = cost, mPortal = portal, mActive = true, }); }
/* * @private */ public static bool areCollinear(SimpleLine line1, SimpleLine line2, float errorMargin = 0.0001f) { // Figure out if the two lines are equal by looking at the area of the triangle formed // by their points double area1 = triarea2(line1.Start, line1.End, line2.Start); double area2 = triarea2(line1.Start, line1.End, line2.End); if (almostEqual(area1, 0, errorMargin) && almostEqual(area2, 0, errorMargin)) { return(true); } return(false); }
/// <summary>Creates a new PositionedNode.</summary> public static TNode Create(int id, NavArea <TNode, TLink> parentNavArea, NavArea <TNode, TLink> otherParentNavArea, SimpleLine portalForFirstParent) { Point portalCenter = _LineCenter(portalForFirstParent); var node = new TNode(); node.mID = id; node.mParentNavArea1 = parentNavArea; node.mParentNavArea2 = otherParentNavArea; node.mPortalSide1 = portalForFirstParent; node.mPortalSide1ParentAreaId = parentNavArea.ID; node.mPortalSide2 = NavMesh <TNode, TLink> ._GetInvertedLine(portalForFirstParent); node.mPortalSide2ParentAreaId = otherParentNavArea.ID; node.Position.X = (float)portalCenter.X; node.Position.Y = (float)portalCenter.Y; //node.mActive = true; return(node); }
public static SimpleLine _GetInvertedLine(SimpleLine line) { return(new SimpleLine(line.End, line.Start)); }
// v4 phaser-navmesh updated /// <summary>Check two collinear line segments to see if they overlap by sorting the points.</summary> /// <param name="line1">Polygon's edge</param> /// <param name="line2">Other polygon's edge</param> /// <returns>Line Segment of edges where they overlap or null id they don't overlap.</returns> /// <remarks> /// Algorithm source: http://stackoverflow.com/a/17152247 /// </remarks> private SimpleLine _GetSegmentOverlap(SimpleLine line1, SimpleLine line2, bool horisontal, bool swapStartEnd) { var pointsOfLines = new RLineAndPoint[] { new RLineAndPoint(line1, line1.Start), new RLineAndPoint(line1, line1.End), new RLineAndPoint(line2, line2.Start), new RLineAndPoint(line2, line2.End) }; if (horisontal) { Array.Sort( pointsOfLines, (a, b) => { // If lines have same Y, sort by X if (a.Point.X < b.Point.X) { return(-1); } else if (a.Point.X > b.Point.X) { return(1); } return(0); } ); } else { Array.Sort( pointsOfLines, (a, b) => { // If lines have same X, sort by Y if (a.Point.Y < b.Point.Y) { return(-1); } else if (a.Point.Y > b.Point.Y) { return(1); } return(0); } ); } // If the first two points in the array come from the same line, no overlap bool noOverlap = pointsOfLines[0].Line == pointsOfLines[1].Line; // If the two middle points in the array are the same coordinates, then there is a // single point of overlap. bool singlePointOverlap = pointsOfLines[1].Point == pointsOfLines[2].Point; if (noOverlap || singlePointOverlap) { return(null); } else { if (swapStartEnd) { return(new SimpleLine(ref pointsOfLines[2].Point, ref pointsOfLines[1].Point)); } else { return(new SimpleLine(ref pointsOfLines[1].Point, ref pointsOfLines[2].Point)); } } }
public RLineAndPoint(SimpleLine line, Point point) { Line = line; Point = point; }