Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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));
        }
Ejemplo 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() }
            });
        }
Ejemplo 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));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Edge constructor by an array of coordinates
        /// </summary>
        /// <param name="coordinates"></param>
        /// <returns name="edge">edge</returns>
        public static Edge ByCoordinatesArray(double[] coordinates)
        {
            if (coordinates.Count() != 6)
            {
                throw new Exception("Not 6 coordinates provided");
            }
            Vertex start = Vertex.ByCoordinates(coordinates[0], coordinates[1], coordinates[2]);
            Vertex end   = Vertex.ByCoordinates(coordinates[3], coordinates[4], coordinates[5]);

            return(new Edge(start, end));
        }
Ejemplo n.º 6
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 }
            });
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        public static Polygon ByCenterRadiusAndSides(Vertex center, double radius, int sides)
        {
            // TODO: create polygon by plane?
            if (sides < 3)
            {
                throw new ArgumentOutOfRangeException("sides", "Any polygon must have at least 3 sides.");
            }
            List <Vertex> vertices = new List <Vertex>();
            double        angle    = (Math.PI * 2) / sides;

            for (var i = 0; i < sides; i++)
            {
                var vertex = Vertex.ByCoordinates(
                    (Math.Cos(i * angle) * radius) + center.X,
                    (Math.Sin(i * angle) * radius) + center.Y,
                    center.Z
                    );
                vertices.Add(vertex);
            }

            return(new Polygon(vertices));
        }
Ejemplo n.º 9
0
 internal static Vertex ToVertex(this DSPoint point)
 {
     return(Vertex.ByCoordinates(point.X, point.Y, point.Z));
 }
Ejemplo n.º 10
0
 public Vertex AsVertex()
 {
     return(Vertex.ByCoordinates(this.X, this.Y, this.Z));
 }