-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptUtilities.cs
More file actions
111 lines (85 loc) · 2.72 KB
/
ScriptUtilities.cs
File metadata and controls
111 lines (85 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace ScriptUtilities
{
//this namespace wil contain many useful utilites for vectors, floats, math, and otherwise
//add as you go, create multiple subclasses for each type of utility
public static class Vector3Utils
{
//designated class in the namespace for vector3
public static Vector3 Add (Vector3 a, Vector3 b)
{
return new Vector3 (a.x + b.x, a.y + b.y, a.z + b.z);
}
public static Vector3 Subtract (Vector3 a, Vector3 b)
{
return new Vector3 (a.x - b.x, a.y - b.y, a.z - b.z);
}
public static Vector3 Multiply (Vector3 a, Vector3 b)
{
return new Vector3 (a.x * b.x, a.y * b.y, a.z * b.z);
}
public static Vector3 Divide (Vector3 a, Vector3 b)
{
return new Vector3 (a.x / b.x, a.y / b.y, a.z / b.z);
}
public static Vector3 Divide (Vector3 a, float b)
{
return new Vector3 (a.x / b, a.y / b, a.z / b);
}
public static Vector3 Divide (Vector3 a, int b)
{
return new Vector3 (a.x / b, a.y / b, a.z / b);
}
public static Vector3 SetY (Vector3 a, float y)
{
return new Vector3 (a.x, y, a.z);
}
}
public static class CircleUtils
{
public static Vector2 CalculatePointOnCircle (Vector2 origin, float angle, float radius)
{
/*
where
x,y are the destination coordinates
cx,cy are the origin coordinates
r is the radius
a is the degrees in radians clockwise from the top
x = cx + r * cos(a)
y = cy + r * sin(a)
*/
Vector2 position = Vector2.zero;
position.x = origin.x + (radius * Mathf.Cos (angle * Mathf.Deg2Rad));
position.y = origin.y + (radius * Mathf.Sin (angle * Mathf.Deg2Rad));
return position;
}
public static Vector3 CalculatePointOnCircle (Vector3 origin, float angle, float radius)
{
/*
where
x,y are the destination coordinates
cx,cy are the origin coordinates
r is the radius
a is the degrees in radians clockwise from the top
x = cx + r * cos(a)
y = cy + r * sin(a)
*/
Vector3 position = Vector3.zero;
position.x = origin.x + (radius * Mathf.Cos (angle * Mathf.Deg2Rad));
position.y = origin.y;
position.z = origin.z + (radius * Mathf.Sin (angle * Mathf.Deg2Rad));
return position;
}
public static List<Vector3> CalculatePointsOnCircle (int n, float r, Vector3 o)
{
List<Vector3> posList = new List<Vector3> ();
float aiDeg = (360 / n);
for (int i = 0; i < n; i++) {
posList.Add (CalculatePointOnCircle (o, aiDeg * i, r));
}
return posList;
}
}
}