Esempio n. 1
0
        /// <summary>
        /// Radian angle from a centre to another point
        /// </summary>
        /// <param name="centre"></param>
        /// <param name="point"></param>
        /// <returns name="rad">Radians</returns>
        internal static double RadAngle(DSPoint centre, DSPoint point)
        {
            Vertex v1 = Vertex.ByCoordinates(centre.X, centre.Y, centre.Z);
            Vertex v2 = Vertex.ByCoordinates(point.X, point.Y, point.Z);

            return(Vertex.RadAngle(v1, v2));
        }
Esempio n. 2
0
        public static Surface IsovistFromPoint(BaseGraph baseGraph, DSPoint point)
        {
            if (baseGraph == null)
            {
                throw new ArgumentNullException("graph");
            }
            if (point == null)
            {
                throw new ArgumentNullException("point");
            }

            Vertex origin = Vertex.ByCoordinates(point.X, point.Y, point.Z);

            List <Vertex>  vertices = Graphical.Graphs.VisibilityGraph.VertexVisibility(origin, baseGraph.graph);
            List <DSPoint> points   = vertices.Select(v => Points.ToPoint(v)).ToList();
            Surface        isovist;

            // TODO: Implement better way of checking if polygon is self intersecting

            Autodesk.DesignScript.Geometry.Polygon polygon = Autodesk.DesignScript.Geometry.Polygon.ByPoints(points);


            //fix back
            //
            // if(Graphical.Geometry.Polygon.Intersection(polygon).Length > 0)
            // {
            //     points.Add(point);
            //     polygon = Polygon.by(points);
            //
            // }

            return(Surface.ByPatch(polygon));
        }
Esempio n. 3
0
        public static Dictionary <string, object> ShortestPath(VisibilityGraph visGraph, DSPoint origin, DSPoint destination)
        {
            if (visGraph == null)
            {
                throw new ArgumentNullException("visGraph");
            }
            if (origin == null)
            {
                throw new ArgumentNullException("origin");
            }
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }

            Vertex gOrigin      = Vertex.ByCoordinates(origin.X, origin.Y, origin.Z);
            Vertex gDestination = Vertex.ByCoordinates(destination.X, destination.Y, destination.Z);

            Graphical.Graphs.VisibilityGraph visibilityGraph = visGraph.graph as Graphical.Graphs.VisibilityGraph;

            BaseGraph baseGraph = new BaseGraph()
            {
                graph = Graphical.Graphs.VisibilityGraph.ShortestPath(visibilityGraph, gOrigin, gDestination)
            };

            return(new Dictionary <string, object>()
            {
                { "graph", baseGraph },
                { "length", baseGraph.graph.Edges.Select(e => e.Length).Sum() }
            });
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a Graph by a set of boundary and internal polygons.
        /// </summary>
        /// <param name="boundaries">Boundary polygons</param>
        /// <param name="internals">Internal polygons</param>
        /// <returns name="baseGraph">Base graph</returns>
        public static BaseGraph ByBoundaryAndInternalPolygons(List <Polygon> boundaries, [DefaultArgument("[]")] List <Polygon> internals)
        {
            if (boundaries == null)
            {
                throw new NullReferenceException("boundaryPolygons");
            }
            if (internals == null)
            {
                throw new NullReferenceException("internalPolygons");
            }
            List <Polygon> input = new List <Polygon>();

            foreach (Polygon pol in boundaries)
            {
                var     vertices = pol.Vertices.Select(pt => Vertex.ByCoordinates(pt.X, pt.Y, pt.Z)).ToList();
                Polygon gPol     = Polygon.ByVertices(vertices, true);
                input.Add(gPol);
            }

            foreach (Polygon pol in internals)
            {
                var     vertices = pol.Vertices.Select(pt => Vertex.ByCoordinates(pt.X, pt.Y, pt.Z)).ToList();
                Polygon gPol     = Polygon.ByVertices(vertices, false);
                input.Add(gPol);
            }

            return(new BaseGraph(input));
        }
Esempio n. 5
0
        internal static bool DoesIntersect(Line line, DSPoint point)
        {
            Edge   edge   = Edge.ByStartVertexEndVertex(Points.ToVertex(line.StartPoint), Points.ToVertex(line.EndPoint));
            Vertex vertex = Points.ToVertex(point);

            return(vertex.OnEdge(edge));
        }
Esempio n. 6
0
        /// <summary>
        /// Radian angle between two points from a centre.
        /// </summary>
        /// <param name="centre"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public static double StartEndRadiansFromCentre(DSPoint centre, DSPoint start, DSPoint end)
        {
            Vertex c = ToVertex(centre);
            Vertex s = ToVertex(start);
            Vertex e = ToVertex(end);

            return(Vertex.ArcRadAngle(c, s, e));
        }
Esempio n. 7
0
        internal static bool PolygonContainsPoint(Polygon polygon, DSPoint point)
        {
            Vertex  vertex   = Points.ToVertex(point);
            var     vertices = polygon.Vertices.Select(p => Points.ToVertex(point)).ToList();
            Polygon gPolygon = null;

            gPolygon = Polygon.ByVertices(vertices, false);

            return(gPolygon.ContainsVertex(vertex));
        }
Esempio n. 8
0
        public static Dictionary <string, object> BuildPolygons(List <Line> lines)
        {
            if (lines == null)
            {
                throw new ArgumentNullException("lines");
            }
            if (lines.Count < 2)
            {
                throw new ArgumentException("Needs 2 or more lines", "lines");
            }

            BaseGraph g = BaseGraph.ByLines(lines);

            g.graph.BuildPolygons();

            var            gPolygons    = g.graph.Polygons;
            List <Polygon> dsPolygons   = new List <Polygon>();
            List <Line>    dsLines      = new List <Line>();
            List <Edge>    polygonEdges = new List <Edge>();

            foreach (Polygon gP in gPolygons)
            {
                var vertices = gP.Vertices.Select(v => Vertex.ByCoordinates(v.X, v.Y, v.Z)).ToList();
                if (gP.IsClosed)
                {
                    dsPolygons.Add(Polygon.ByVertices(vertices));
                }
                else if (gP.Edges.Count > 1)
                {
                    foreach (Edge edge in gP.Edges)
                    {
                        DSPoint start = Points.ToPoint(edge.StartVertex);
                        DSPoint end   = Points.ToPoint(edge.EndVertex);
                        dsLines.Add(Line.ByStartPointEndPoint(start, end));
                    }
                }
                else
                {
                    DSPoint start = Points.ToPoint(gP.Edges.First().StartVertex);
                    DSPoint end   = Points.ToPoint(gP.Edges.First().EndVertex);
                    dsLines.Add(Line.ByStartPointEndPoint(start, end));
                }
            }

            return(new Dictionary <string, object>()
            {
                { "polygons", dsPolygons },
                { "ungrouped", dsLines }
            });
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a graph by a set of closed polygons
        /// </summary>
        /// <param name="polygons">Polygons</param>
        /// <returns name="baseGraph">Base graph</returns>
        public static BaseGraph ByPolygons(List <Polygon> polygons)
        {
            if (polygons == null)
            {
                throw new NullReferenceException("polygons");
            }
            List <Polygon> input = new List <Polygon>();

            foreach (Polygon pol in polygons)
            {
                var     vertices = pol.Vertices.Select(pt => Vertex.ByCoordinates(pt.X, pt.Y, pt.Z)).ToList();
                Polygon gPol     = Polygon.ByVertices(vertices, false);
                input.Add(gPol);
            }

            return(new BaseGraph(input));
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a new Graph by a set of lines.
        /// </summary>
        /// <param name="lines">Lines</param>
        /// <returns name="baseGraph">Base Graph</returns>
        public static BaseGraph ByLines(List <Line> lines)
        {
            if (lines == null)
            {
                throw new NullReferenceException("lines");
            }
            BaseGraph g = new BaseGraph()
            {
                graph = new Graphical.Graphs.Graph()
            };

            foreach (Line line in lines)
            {
                Vertex start = Geometry.Points.ToVertex(line.StartPoint);
                Vertex end   = Geometry.Points.ToVertex(line.EndPoint);
                g.graph.AddEdge(Edge.ByStartVertexEndVertex(start, end));
            }
            return(g);
        }
Esempio n. 11
0
        internal static Dictionary <Vertex, List <DSCurve> > CurvesDependency(List <DSCurve> curves)
        {
            Dictionary <Vertex, List <DSCurve> > graph = new Dictionary <Vertex, List <DSCurve> >();

            foreach (DSCurve curve in curves)
            {
                Vertex         start     = Points.ToVertex(curve.StartPoint);
                Vertex         end       = Points.ToVertex(curve.EndPoint);
                List <DSCurve> startList = new List <DSCurve>();
                List <DSCurve> endList   = new List <DSCurve>();
                if (graph.TryGetValue(start, out startList))
                {
                    startList.Add(curve);
                }
                else
                {
                    graph.Add(start, new List <DSCurve>()
                    {
                        curve
                    });
                }

                if (graph.TryGetValue(end, out endList))
                {
                    endList.Add(curve);
                }
                else
                {
                    graph.Add(end, new List <DSCurve>()
                    {
                        curve
                    });
                }
            }
            return(graph);
        }
Esempio n. 12
0
 internal static DSPoint ToPoint(this Vertex vertex)
 {
     return(DSPoint.ByCoordinates(vertex.X, vertex.Y, vertex.Z));
 }
Esempio n. 13
0
 internal static Vertex ToVertex(this DSPoint point)
 {
     return(Vertex.ByCoordinates(point.X, point.Y, point.Z));
 }
Esempio n. 14
0
        //Vector-plane intersection https://math.stackexchange.com/questions/100439/determine-where-a-vector-will-intersect-a-plane

        #region Public Methods


        /// <summary>
        /// Returns the mid point between two points.
        /// </summary>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        /// <returns></returns>
        public static DSPoint MidPoint(DSPoint point1, DSPoint point2)
        {
            Vertex midVertex = Vertex.MidVertex(ToVertex(point1), ToVertex(point2));

            return(ToPoint(midVertex));
        }
Esempio n. 15
0
 internal static void AddColouredVertex(IRenderPackage package, Vertex vertex, DSCore.Color color)
 {
     package.AddPointVertex(vertex.X, vertex.Y, vertex.Z);
     package.AddPointVertexColor(color.Red, color.Green, color.Blue, color.Alpha);
 }
Esempio n. 16
0
        public static Dictionary <string, object> GroupCurves(List <DSCurve> curves)
        {
            if (curves == null)
            {
                throw new ArgumentNullException("lines");
            }
            if (curves.Count < 2)
            {
                throw new ArgumentException("Needs 2 or more lines", "lines");
            }

            Dictionary <Vertex, List <DSCurve> > graph    = CurvesDependency(curves);
            Dictionary <int, List <DSCurve> >    grouped  = new Dictionary <int, List <DSCurve> >();
            Dictionary <Vertex, int>             vertices = new Dictionary <Vertex, int>();

            foreach (Vertex v in graph.Keys)
            {
                // If already belongs to a polygon or is not a polygon vertex or already computed
                if (vertices.ContainsKey(v) || graph[v].Count > 2)
                {
                    continue;
                }

                // grouped.Count() translates to the number of different groups created
                vertices.Add(v, grouped.Count());
                grouped.Add(vertices[v], new List <DSCurve>());

                foreach (DSCurve curve in graph[v])
                {
                    var     startVertex = Points.ToVertex(curve.StartPoint);
                    var     endVertex   = Points.ToVertex(curve.EndPoint);
                    DSCurve nextCurve   = curve;
                    Vertex  nextVertex  = (startVertex.Equals(v)) ? endVertex : startVertex;

                    while (!vertices.ContainsKey(nextVertex))
                    {
                        vertices.Add(nextVertex, vertices[v]);
                        grouped[vertices[v]].Add(nextCurve);

                        // Next vertex doesn't have any other curve connected.
                        if (graph[nextVertex].Count < 2)
                        {
                            break;
                        }

                        nextCurve   = graph[nextVertex].Where(c => !c.Equals(nextCurve)).First();
                        startVertex = Points.ToVertex(nextCurve.StartPoint);
                        endVertex   = Points.ToVertex(nextCurve.EndPoint);
                        nextVertex  = (startVertex.Equals(nextVertex)) ? endVertex : startVertex;
                    }
                    if (!grouped[vertices[v]].Last().Equals(nextCurve))
                    {
                        grouped[vertices[v]].Add(nextCurve);
                    }
                }
            }

            List <PolyCurve> polyCurves = new List <PolyCurve>();
            List <DSCurve>   ungrouped  = new List <DSCurve>();

            foreach (var group in grouped.Values)
            {
                if (group.Count > 1)
                {
                    polyCurves.Add(PolyCurve.ByJoinedCurves(group));
                }
                else
                {
                    ungrouped.Add(group.First());
                }
            }

            return(new Dictionary <string, object>()
            {
                { "polycurves", polyCurves },
                { "ungrouped", ungrouped }
            });
        }