public NewChargePoint RunLaplace() { int numberSpawned = 0; //Step 1 //weigh all nodes, then randomly select one according to a weighting //http://gamma.cs.unc.edu/FRAC/laplacian_large.pdf //Step 2 //Add a new point charge at the growth site. //Step 3 //Update the potential at all the candidate sites accordingto Eqn. 11. //Step 4 -> 5 //Add the new candidate sites surrounding the growth site. //Calculate the potential at new candidate sites Eqn. 10 if (numberSpawned < maxNumberspawned) { NewChargePoint chosenNode = StepOne(); chosenNode = StepTwo(chosenNode); StepThree(chosenNode); numberSpawned++; StepFour(chosenNode); } return(hitNode); }
//Update the potential at all the candidate sites accordingto Eqn. 11. void StepThree(NewChargePoint recentCharge) { foreach (NewChargePoint i in candidateCharges) { i.potential = i.potential + (1 - (ROne / (recentCharge.potential)));///r = the potential from the point charge at step one } }
List <NewChargePoint> GetLightningPathFromNode(NewChargePoint aNode) { List <NewChargePoint> lightningList = new List <NewChargePoint>(); lightningList.Add(aNode); NewChargePoint currentNode; currentNode = aNode; while (currentNode.parentCharge != null) { currentNode = currentNode.parentCharge; lightningList.Add(currentNode); } return(lightningList); }
public void InitiateLaplace() { //calculate boundary constants ROne = h / 2; //spawn initial charge collisionPositions.Add(new Vector3(0, 0, 0)); NewChargePoint startingCharge = ScriptableObject.CreateInstance <NewChargePoint>(); startingCharge.potential = 26;//according to the reference material, 26 for the spawned charge, -1 for the other charges //changed to 17 to prevent upwards lightning spawnedCharges.Add(startingCharge); //add surrounding candidate charges SpawnStartingOctantPreset(startingCharge); }
//add the selected node to the spawned category NewChargePoint StepTwo(NewChargePoint newNode) { candidateCharges.Remove(newNode); newNode.parentCharge.childSpawnedCharges.Add(newNode); //change the node to completed node spawnedCharges.Add(newNode); //spawncheck Collider[] hitCheck = Physics.OverlapSphere(newNode.chargePointRelativePosition + transform.position, .5f); if (hitCheck.Length > 0) { Debug.Log(hitCheck.Length); hitNode = newNode; } return(newNode); }
//Step 4 - Add the new candidate sites surrounding the growth site. void StepFour(NewChargePoint chosenNode) { //get the recent spawned charge position Vector3 newPointPosition = chosenNode.chargePointRelativePosition; //add charges based on a 3x3x3 octant List <NewChargePoint> newCharges = new List <NewChargePoint>(); int jNum = 3; if (genType == GenerationTypes.SemiSphere) { jNum = 2; } for (int i = 0; i < 3; i++) { for (int j = 0; j < jNum; j++) { for (int k = 0; k < 3; k++) { Vector3 checkPos = newPointPosition + new Vector3(i - 1, j - 1, k - 1); if (!collisionPositions.Contains(checkPos)) { Vector3 pos = checkPos + gameObject.transform.position; NewChargePoint newCharge = ScriptableObject.CreateInstance <NewChargePoint>(); newCharge.chargePointRelativePosition = checkPos; collisionPositions.Add(new Vector3(i - 1, j - 1, k - 1) + newPointPosition); newCharges.Add(newCharge); newCharge.parentCharge = chosenNode; } } } } StepFive(newCharges); }
void SpawnStartingOctantPreset(NewChargePoint spawnCharge) { //get the recent spawned charge position Vector3 newPointPosition = new Vector3(0, 0, 0); //add charges based on a 3x3x3 octant List <NewChargePoint> newCharges = new List <NewChargePoint>(); int jNum = 3; if (genType == GenerationTypes.SemiSphere) { jNum = 2; } for (int i = 0; i < 3; i++) //x { for (int j = 0; j < jNum; j++) //y { for (int k = 0; k < 3; k++) //z { Vector3 checkPos = newPointPosition + new Vector3(i - 1, j - 1, k - 1); if (newPointPosition != checkPos) { Vector3 pos = checkPos + gameObject.transform.position; NewChargePoint newCharge = ScriptableObject.CreateInstance <NewChargePoint>(); newCharge.chargePointRelativePosition = checkPos; collisionPositions.Add(new Vector3(i - 1, j - 1, k - 1)); newCharges.Add(newCharge); newCharge.parentCharge = spawnCharge; } } } } StepFive(newCharges); }
public void RenderFromNode(NewChargePoint givenNode) { renderPath = GetLightningPathFromNode(givenNode); DrawFromList(); }