private List <TNetMesh> ConstructTNetMeshFromCellmap(List <VFace> cellmap) { List <Vertex> vertices = new List <Vertex>(); List <TNetMesh> result = new List <TNetMesh>(); TriangleNet.Configuration config = new TriangleNet.Configuration(); SweepLine sweepline = new SweepLine(); foreach (VFace face in cellmap) { vertices.Clear(); foreach (VHEdge he in face.EnumerateEdges()) { Vertex v = new Vertex(he.Origin.X, he.Origin.Y); v.Z = he.Origin.Z; if (!vertices.Contains(v)) { vertices.Add(v); } } TNetMesh tMesh = (TNetMesh)sweepline.Triangulate(vertices, config); result.Add(tMesh); } return(result); }
public GameObject voronoiFaceToGO(TriangleNet.Topology.DCEL.Face face) { GameObject cell; if (face.Bounded) { cell = new GameObject("FaceID: " + face.ID); MeshFilter mFilter = cell.AddComponent <MeshFilter>(); MeshRenderer mRender = cell.AddComponent <MeshRenderer>(); mRender.material = new Material(Shader.Find("Diffuse")); mRender.material.color = new Color(1f, 1f, 1f); List <Vertex> vertices = new List <Vertex>(); foreach (TriangleNet.Topology.DCEL.HalfEdge he in face.EnumerateEdges()) { Vertex v = new Vertex(he.Origin.X, he.Origin.Y); vertices.Add(v); } SweepLine sl = new SweepLine(); TriangleNet.Configuration conf = new TriangleNet.Configuration(); TriangleNet.Mesh tMeshCell = (TriangleNet.Mesh)sl.Triangulate(vertices, conf); mFilter.mesh = OsgiViz.Helperfunctions.convertTriangleNETMesh(tMeshCell); } else { cell = new GameObject("unbounded cell"); } return(cell); }
/// <summary> /// Initializes a new instance of the <see cref="BentleyOttmannAlgorithm" /> class. /// </summary> /// <param name="source">The coordinates of the line string.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public BentleyOttmannAlgorithm(IEnumerable <Coordinate> source, PrecisionModel precisionModel) { this.Source = source ?? throw new ArgumentNullException(nameof(source)); this.PrecisionModel = precisionModel ?? PrecisionModel.Default; this.eventQueue = new EventQueue(source); this.sweepLine = new SweepLine(source, this.PrecisionModel); this.hasResult = false; }
/// <summary> /// Determines if two _polygonsDict are intersecting /// </summary> /// <param name="polygon"></param> /// <returns></returns> public bool Intersects(Polygon polygon) { if (!this.BoundingBox.Intersects(polygon.BoundingBox)) { return(false); } var sw = new SweepLine(this, polygon, SweepLineType.Intersects); return(sw.HasIntersection()); }
public List <Edge> FindIntersection(IEnumerable <Edge> edges) { intersected = null; var sweepLine = new SweepLine <IntersectionSweepEvent, IntersectionStatusItem>(); List <LineSegment> segments = CreateSegments(edges); IEnumerable <E> events = CreateEvents(segments) as IEnumerable <E>; sweepLine.InitializeEvents(events); sweepLine.VerticalSweep(HandleEvent); return(intersected); }
/// <summary> /// Initializes a new instance of the <see cref="ShamosHoeyAlgorithm" /> class. /// </summary> /// <param name="source">The line string.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public ShamosHoeyAlgorithm(IBasicLineString source, PrecisionModel precisionModel = null) { if (source == null) { throw new ArgumentNullException("source", "The source is null."); } PrecisionModel = precisionModel ?? PrecisionModel.Default; _eventQueue = new PresortedEventQueue(source.Coordinates); _sweepLine = new SweepLine(source.Coordinates, precisionModel); _hasResult = false; }
/// <summary> /// Initializes a new instance of the <see cref="ShamosHoeyAlgorithm" /> class. /// </summary> /// <param name="source">The collection of coordinates representing multiple line strings.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public ShamosHoeyAlgorithm(IEnumerable <IBasicLineString> source, PrecisionModel precisionModel = null) { if (source == null) { throw new ArgumentNullException("source", "The source is null."); } PrecisionModel = precisionModel ?? PrecisionModel.Default; _eventQueue = new PresortedEventQueue(source.Select(lineString => lineString == null ? null : lineString.Coordinates)); _sweepLine = new SweepLine(source.Select(hole => hole.Coordinates), precisionModel); _hasResult = false; }
/// <summary> /// Initializes a new instance of the <see cref="ShamosHoeyAlgorithm" /> class. /// </summary> /// <param name="source">The collection of coordinates representing multiple line strings.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public ShamosHoeyAlgorithm(IEnumerable <IEnumerable <Coordinate> > source, PrecisionModel precisionModel) { if (source == null) { throw new ArgumentNullException(nameof(source)); } this.PrecisionModel = precisionModel ?? PrecisionModel.Default; this.eventQueue = new PresortedEventQueue(source); this.sweepLine = new SweepLine(source, precisionModel); this.hasResult = false; }
/// <summary> /// Initializes a new instance of the <see cref="BentleyOttmannAlgorithm" /> class. /// </summary> /// <param name="source">The coordinates of the line string.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public BentleyOttmannAlgorithm(IList <Coordinate> source, PrecisionModel precisionModel = null) { if (source == null) { throw new ArgumentNullException("source", "The source is null."); } _source = source; PrecisionModel = precisionModel ?? PrecisionModel.Default; _eventQueue = new EventQueue(source); _sweepLine = new SweepLine(source, PrecisionModel); _hasResult = false; }
public void TestTriangulateSweepLine() { var t = new SweepLine(); var vertices = GetVertices(); var mesh = t.Triangulate(vertices, new Configuration()); Assert.AreEqual(6, vertices.Count); Assert.AreEqual(6, mesh.Vertices.Count); Assert.AreEqual(1, mesh.Vertices .Where(v => v.Type == VertexType.UndeadVertex) .Count()); }
private void Execute(IReadOnlyCollection <Segment> segments, int expectedCount) { var svg = segments.ToSvg(); var intersections = new SweepLine(segments, true).FindIntersections().ToArray(); Console.WriteLine("Intersections count: {0}", intersections.Length); foreach (var intersection in intersections) { Console.WriteLine(intersection.U.ToString() + " " + intersection.V.ToString()); } Assert.AreEqual(expectedCount, intersections.Length); }
// Use this for initialization void Start() { TriangleNet.Configuration conf = new TriangleNet.Configuration(); List <Vertex> vertices = OsgiViz.Helperfunctions.createPointsOnPlane(1f, 1f, 50, 50, 1f, new System.Random()); SweepLine sl = new SweepLine(); //TriangleNet.Mesh tMesh = (TriangleNet.Mesh)TriangleNet.Meshing.GenericMesher.StructuredMesh(1f, 1f, 10, 10); TriangleNet.Mesh tMesh = (TriangleNet.Mesh)sl.Triangulate(vertices, conf); TriangleNet.Voronoi.BoundedVoronoi voronoi = new TriangleNet.Voronoi.BoundedVoronoi(tMesh); foreach (TriangleNet.Topology.DCEL.Face vf in voronoi.Faces) { voronoiFaceToGO(vf); } }
/// <summary> /// Initializes a new instance of the <see cref="BentleyOttmannAlgorithm" /> class. /// </summary> /// <param name="source">The collection of coordinates representing multiple line strings.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public BentleyOttmannAlgorithm(IEnumerable <IList <Coordinate> > source, PrecisionModel precisionModel = null) { if (source == null) { throw new ArgumentNullException("source", "The source is null."); } _source = new List <Coordinate>(); foreach (IList <Coordinate> linestring in source) { (_source as List <Coordinate>).AddRange(linestring); } PrecisionModel = precisionModel ?? PrecisionModel.Default; _eventQueue = new EventQueue(source); _sweepLine = new SweepLine(source, PrecisionModel); _hasResult = false; }
public static bool isSimple(IList <Vector3> poly) { PriorityHeap <VertexEv> evQueue = setupEvQueue(poly); SweepLine SL = new SweepLine(poly); //Debug.LogWarning("Queue size=" + evQueue.Count); while (!evQueue.Empty) { VertexEv ev = evQueue.Pop(); if (ev.type == VertexEv.vType.LEFT) { int idx = SL.Add(ev.edge); //Debug.Log("Left: " + idx + "/" + SL.Count); if (SL.intersect(idx, idx - 1)) { return(false); } if (SL.intersect(idx, idx + 1)) { return(false); } } else // right vertex { int idx = SL.Find(ev.edge); //Debug.Log("Right: " + idx + "/" + SL.Count); if (SL.intersect(idx - 1, idx + 1)) { return(false); } SL.Remove(idx); } } return(true); }
/* * List<List<Vector3>> decompose(List<Vector3> poly) { * * } */ // returns one intersection point or null if polygon is simple static IntersectionPoint oneIntersection(IList <Vector3> poly) { PriorityHeap <VertexEv> evQueue = setupEvQueue(poly); SweepLine SL = new SweepLine(poly); IntersectionPoint I; while (!evQueue.Empty) { VertexEv ev = evQueue.Pop(); if (ev.type == VertexEv.vType.LEFT) { int idx = SL.Add(ev.edge); I = SL.GetIntersectionPoint(idx, idx - 1); if (I != null) { return(I); } I = SL.GetIntersectionPoint(idx, idx + 1); if (I != null) { return(I); } } else // right vertex { int idx = SL.Find(ev.edge); I = SL.GetIntersectionPoint(idx - 1, idx + 1); if (I != null) { return(I); } SL.Remove(idx); } } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="BentleyOttmannAlgorithm" /> class. /// </summary> /// <param name="source">The collection of coordinates representing multiple line strings.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public BentleyOttmannAlgorithm(IEnumerable <IEnumerable <Coordinate> > source, PrecisionModel precisionModel) { if (source == null) { throw new ArgumentNullException(nameof(source)); } List <Coordinate> coordinates = new List <Coordinate>(); foreach (IEnumerable <Coordinate> linestring in source) { coordinates.AddRange(linestring); } this.Source = coordinates; this.PrecisionModel = precisionModel ?? PrecisionModel.Default; this.eventQueue = new EventQueue(source); this.sweepLine = new SweepLine(source, this.PrecisionModel); this.hasResult = false; }
public BoundedVoronoi CreateRelaxedVoronoi(int lloydRelaxations, float cellScale, int seed) { System.Random random = new System.Random(seed); List <Vertex> startingVertices = CreatePointsOnPlane(cellScale, cellScale, 50, 50, 1.0f, random); List <Vertex> vertices = new List <Vertex>(); TriangleNet.Configuration config = new TriangleNet.Configuration(); SweepLine sweepline = new SweepLine(); TNetMesh tMesh = (TNetMesh)sweepline.Triangulate(startingVertices, config); BoundedVoronoi voronoi = new BoundedVoronoi(tMesh); for (int i = 0; i < lloydRelaxations; i++) { foreach (VFace face in voronoi.Faces) { if (CheckCell(face)) { Vertex newCentroid = new Vertex(0, 0); int vertexCount = 0; foreach (VHEdge edge in face.EnumerateEdges()) { newCentroid.X += edge.Origin.X; newCentroid.Y += edge.Origin.Y; vertexCount++; } newCentroid.X /= vertexCount; newCentroid.Y /= vertexCount; vertices.Add(newCentroid); } } tMesh = (TNetMesh)sweepline.Triangulate(vertices, config); voronoi = new BoundedVoronoi(tMesh); vertices.Clear(); } return(voronoi); }
// Update is called once per frame void Update() { bool update = UpdateTimer(Time.deltaTime); bool instantMove = Input.GetKeyDown(KeyCode.Space); if (update || instantMove) { Grid grid = Grid.Ins; Tetramino tetramino = tetraminoMono.tetramino; Vector2Int offset = Vector2Int.down; bool spawnNewTetramino = false; if (instantMove) { //Vector2Int projectionPos = projection.projection.GetComponent<TetraminoMono>().tetramino.centerPos; //Vector2Int tetraminoPos = tetramino.centerPos; //offset = projectionPos - tetraminoPos; spawnNewTetramino = true; } else { bool collision = Grid.Collision(grid, tetramino, Vector2Int.down, Tetramino.RotationType.None); if (collision) { //Debug.Log("collision"); spawnNewTetramino = true; } else { tetraminoMono.TranslateCenterPosition(offset); } } if (spawnNewTetramino) { Tetramino tetraminoProjectionCopy = projection.DropProjection(); //TODO Check exact spawn time SpawnNewTetramino(); SweepLine.Sweep(tetraminoProjectionCopy); } } }
/// <summary> /// simple_Polygon(): test if a Polygon is simple or not /// Input: Pn = a polygon with n vertices V[] /// Return: false(0) = is NOT simple /// true(1) = IS simple /// </summary> /// <param name="polygon"></param> /// <returns></returns> public bool IsSimple(Polygon polygon) { Require.ArgumentNotNull(polygon, nameof(polygon)); EventQueue eventQueue = new EventQueue(polygon); SweepLine sweepLine = new SweepLine(polygon); Event currentEvent; // the current event // This loop processes all events in the sorted queue // Events are only left or right vertices since // No new events will be added (an intersect => Done) while ((currentEvent = eventQueue.Next()) != null) { // while there are events if (currentEvent.EventType == EventType.Left) { // process a left vertex var currentSegment = sweepLine.Add(currentEvent); // add it to the sweep line if (sweepLine.Intersect(currentSegment, currentSegment.Above)) { return(false); // Pn is NOT simple } if (sweepLine.Intersect(currentSegment, currentSegment.Below)) { return(false); // Pn is NOT simple } } else { // processs a right vertex var currentSegment = sweepLine.Find(currentEvent); if (sweepLine.Intersect(currentSegment.Above, currentSegment.Below)) { return(false); // Pn is NOT simple } sweepLine.Remove(currentSegment); // remove it from the sweep line } } return(true); // Pn IS simple }
public static BoundedVoronoi createRelaxedVoronoi(List <Vertex> startingVertices, int numLloydRelaxations) { TriangleNet.Configuration conf = new TriangleNet.Configuration(); SweepLine sl = new SweepLine(); List <Vertex> vertices = new List <Vertex>(); TnetMesh tMesh = (TnetMesh)sl.Triangulate(startingVertices, conf); BoundedVoronoi voronoi = new BoundedVoronoi(tMesh); for (int i = 0; i < numLloydRelaxations; i++) { foreach (VFace face in voronoi.Faces) { if (checkCell(face)) { Vertex newCentroid = new Vertex(0, 0); int vertexCount = 0; foreach (VHEdge edge in face.EnumerateEdges()) { newCentroid.X += edge.Origin.X; newCentroid.Y += edge.Origin.Y; vertexCount++; } newCentroid.X /= vertexCount; newCentroid.Y /= vertexCount; vertices.Add(newCentroid); } } tMesh = (TnetMesh)sl.Triangulate(vertices, conf); voronoi = new BoundedVoronoi(tMesh); vertices.Clear(); } return(voronoi); }
/// <summary> /// Performes a Intersection boolean operation between this polygon and a clipping one. /// </summary> /// <param name="clip"></param> /// <returns></returns> public List <Polygon> Intersection(Polygon clip) { var swLine = new SweepLine(this, clip, SweepLineType.Boolean); return(swLine.ComputeBooleanOperation(BooleanType.Intersection)); }
/// <summary> /// Performes a Difference boolean operation between this polygon and a clipping one. /// </summary> /// <param name="clip"></param> /// <returns></returns> public List <Polygon> Difference(Polygon clip) { var swLine = new SweepLine(this, clip, SweepLineType.Boolean); return(swLine.ComputeBooleanOperation(BooleanType.Differenece)); }
public static void BentleyOttmann(IList <Vector3> poly) { PriorityHeap <VertexEv> evQ = setupEvQueue(poly); SweepLine SL = new SweepLine(poly); Dictionary <int, IntersectionPoint> intersectionPoints = new Dictionary <int, IntersectionPoint>(); IntersectionPoint I; while (!evQ.Empty) { VertexEv ev = evQ.Pop(); if (ev.type == VertexEv.vType.LEFT) { int idx = SL.Add(ev.edge); I = SL.GetIntersectionPoint(idx, idx - 1); if (I != null) // Intersection { int ID = I.Id(poly.Count); if (!intersectionPoints.ContainsKey(ID)) { intersectionPoints[ID] = I; //evQ.Add(new VertexEv(I.v, I.Edge1, I.Edge2, VertexEv.vType.INTERSECT)); evQ.Add(new VertexEv(I)); } } I = SL.GetIntersectionPoint(idx, idx + 1); if (I != null) // intersection { int ID = I.Id(poly.Count); if (!intersectionPoints.ContainsKey(ID)) { intersectionPoints[ID] = I; evQ.Add(new VertexEv(I.P, I.Edge1, I.Edge2, VertexEv.vType.INTERSECT)); } } } else if (ev.type == VertexEv.vType.RIGHT) { int idx = SL.Find(ev.edge); I = SL.GetIntersectionPoint(idx - 1, idx + 1); if (I != null) { int ID = I.Id(poly.Count); if (!intersectionPoints.ContainsKey(ID)) { intersectionPoints[ID] = I; evQ.Add(new VertexEv(I)); } } } else // intersection point // unfinished business ... { } } }
public void SweepLineSpecialTestCase3LinesIntersectingTogetherWithOneIntersectionEndAndStartOf2Lines() { lineIntersectionTester = new SweepLine(); SpecialCase3LinesIntersectingTogetherWithOneIntersectionEndAndStartOf2Lines(); }
public void SweepLineSpecialTestCase3LinesEndAndStartOfEachOther() { lineIntersectionTester = new SweepLine(); SpecialCase3LinesEndAndStartOfEachOther(); }
public void SweepLineSpecialTestCase2PerpendicularLinesIntersectingInStartOfOneOfThem() { lineIntersectionTester = new SweepLine(); SpecialCase2PerpendicularLinesIntersectingInStartOfOneOfThem(); }
public void SweepLineSpecialTestCase21HorizontalLinePerpendicularOn21VerticalLine() { lineIntersectionTester = new SweepLine(); SpecialCase21HorizontalLinePerpendicularOn21VerticalLine(); }
public void SweepLineNormalTestCaseEasyCase2LinesIntersecting5Lines() { lineIntersectionTester = new SweepLine(); CaseEasyCase2LinesIntersecting5Lines(); }
public void SweepLineNormalTestCaseRandom4LinesIntersectingTogether() { lineIntersectionTester = new SweepLine(); CaseRandom4LinesIntersectingTogether(); }
public void SweepLineNormalTestCaseRandom5GroupsOfLineIntersections() { lineIntersectionTester = new SweepLine(); CaseRandom5GroupsOfLineIntersections(); }