# PositionMath_Current

Apr 14th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. ?using UnityEngine;
2. using System.Collections;
3.
4. public class PositionMath {
5.
6.     // This method converts a distance and angle (polar coordinates)
7.     public static Vector3 PolarToCart(float distance, float angle)
8.     {
9.         Vector3 cartPosition = new Vector3(distance * Mathf.Cos(angle), 0, distance * Mathf.Sin(angle));
10.
11.         return cartPosition;
12.     }
13.
14.     public static float SpiralAngle(float armAngle, float starAngle)
15.     {
16.         float angle = armAngle + starAngle;
17.
18.         return angle;
19.     }
20.
21.     // This method returns a random angle between 0 and 2*PI
22.     public static float RandomAngle()
23.     {
24.         float angle = Random.Range(0, 2 * Mathf.PI);
25.
26.         return angle;
27.     }
28.
29.     // This method creates a random polar coordinate then converts and returns it as a Cartesian coordinate
31.     {
33.         float angle = RandomAngle();
34.
35.         Vector3 cartPosition = PolarToCart(distance, angle);
36.
37.         return cartPosition;
38.     }
39.
40.     // This method creates a positon for a planet based on its number in the planetList (see Star Class)
41.     public static Vector3 PlanetPosition(int planetListNumber)
42.     {
43.         float distance = (planetListNumber + 1) * 5;
44.         float angle = RandomAngle();
45.
46.         Vector3 cartPosition = PolarToCart(distance, angle);
47.
48.         return cartPosition;
49.     }
50.
51.     // This method checks if there is a collision when creating a new object, before creating the object.
52.     public static bool CheckCollisions(float minDistBetweenStars, Vector3 cartPosition)
53.     {
54.         bool collision = false;
55.         Collider[] positionCollider = Physics.OverlapSphere(cartPosition, minDistBetweenStars);
56.
57.         if (positionCollider.Length > 0)
58.         {
59.             collision = true;
60.         }
61.
62.         return collision;
63.     }
64.
65.
66.
67.
68.
69.
70.     /*