public Vector3[] GenerateNodeConicLocations(ConicGraphProperties conicGraphProperties, out int[][] edges) { if (conicGraphProperties.FloorsNodesCounts == null) { int[] floorNodesCounts = GraphGeneratorHelper.GenerateFloorNodesCounts(conicGraphProperties.FloorsCount, -1, conicGraphProperties.FloorsCount); conicGraphProperties.FloorsNodesCounts = floorNodesCounts; } int nodesCount = conicGraphProperties.FloorsNodesCounts.Sum(a => a); connections = new Edge[nodesCount, nodesCount]; Vector3[] nodesLocations = _conicGraphGenerator.GenerateGraph(conicGraphProperties, out edges); return(nodesLocations); }
public Vector3[] GenerateGraph(IGraphProperties graphProperties, out int[][] edges) { List <Vector3> nodes = new List <Vector3>(); List <int[]> edgesList = new List <int[]>(); Vector3[] lastNodesFloor = null; Vector3[] currentNodesFloor = null; ConicGraphProperties conicGraphProperties = graphProperties as ConicGraphProperties; float topY = conicGraphProperties.Location.y + conicGraphProperties.Height; float floorHeight = conicGraphProperties.Height / (conicGraphProperties.FloorsCount - 1); for (int floorNo = 0; floorNo < conicGraphProperties.FloorsCount; floorNo++) { float floorY = conicGraphProperties.Location.y + floorNo * floorHeight; float newConeHeight = topY - floorY; float floorRadius = conicGraphProperties.BaseRadius * newConeHeight / conicGraphProperties.Height; if (floorNo > 0) { lastNodesFloor = new Vector3[currentNodesFloor.Length]; currentNodesFloor.CopyTo(lastNodesFloor, 0); } Vector3 partSize = new Vector3(floorRadius / 2, floorHeight, floorRadius / 2); Vector3 floorOrigin = new Vector3(conicGraphProperties.Location.x, floorY, conicGraphProperties.Location.z); currentNodesFloor = GraphGeneratorHelper.GenerateNodeLocationsOnCircle(floorOrigin, floorRadius, conicGraphProperties.FloorsNodesCounts[floorNo], conicGraphProperties.RandomizationPercentage, partSize); nodes.AddRange(currentNodesFloor); edgesList.AddRange(GraphGeneratorHelper.GetEdgesInCircle(currentNodesFloor, nodes)); if (floorNo > 0) { edgesList.AddRange(GraphGeneratorHelper.GetEdgesBetweenTwoSetsAllToAll(lastNodesFloor, currentNodesFloor, nodes)); } } edges = edgesList.ToArray(); return(nodes.ToArray()); }
public void Generate(GraphType graphType, IGraphProperties properties = null, int[][] powerDotLocations = null) { int[][] edges = null; Vector3[] nodesLocations = null; switch (graphType) { case GraphType.Conic: { ConicGraphProperties conicGraphProperties = (ConicGraphProperties)properties ?? new ConicGraphProperties { Location = transform.position, RandomizationPercentage = RandomizationPercentage, Height = ConeHeight, FloorsCount = ConeFloorCount, BaseRadius = ConeRadius }; nodesLocations = GenerateNodeConicLocations(conicGraphProperties, out edges); break; } case GraphType.Cubic: { CubicGraphProperties cubicGraphProperties = (CubicGraphProperties)properties ?? new CubicGraphProperties { RandomizationPercentage = RandomizationPercentage, Location = transform.position, PartsCount = CubePartsCount, Size = CubeSize }; nodesLocations = GenerateNodeCubicLocations(cubicGraphProperties, out edges); break; } case GraphType.Random: { RandomGraphProperties randomGraphProperties = (RandomGraphProperties)properties ?? new RandomGraphProperties { Location = transform.position, NodesCount = RandomNodesCount, EdgesProbability = RandomEdgesProbability, Size = RandomCubeSize }; nodesLocations = GenenerateNodeRandomLocations(randomGraphProperties, out edges); break; } case GraphType.Spheric: { SphericGraphProperties sphericGraphProperties = (SphericGraphProperties)properties ?? new SphericGraphProperties { RandomizationPercentage = RandomizationPercentage, Location = transform.position, FloorsCount = SphereFloorsCount, EdgesProbability = SphereEdgesProbability, Radius = SphereRadius }; nodesLocations = GenerateNodeSphericLocations(sphericGraphProperties, out edges); break; } case GraphType.Spiral: { SpiralGraphProperties spiralGraphProperties = (SpiralGraphProperties)properties ?? new SpiralGraphProperties { Location = transform.position, RandomizationPercentage = RandomizationPercentage, Height = SpiralHeight, FloorsCount = SpiralFloorCount, BaseRadius = SpiralRadius, EdgesProbability = SpiralEdgesProbability }; nodesLocations = GenerateNodeSpiralLocations(spiralGraphProperties, out edges); break; } } InitializeNodes(nodesLocations); InitializeEdges(this.Nodes, edges, powerDotLocations); }