Skip to content

Commit 1a771dd

Browse files
committed
Feat: more math functions
1 parent 3805667 commit 1a771dd

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

Assets/JCSUnity/Scripts/Util/JCS_Mathf.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,19 @@ public static float Tan(float deg)
553553
return Mathf.Tan(DegreeToRadian(deg));
554554
}
555555

556+
/// <summary>
557+
/// Return angle on axis.
558+
/// </summary>
559+
/// <param name="self"> Starting vector. </param>
560+
/// <param name="other"> Compare vector. </param>
561+
/// <param name="axis"> Target axis to get. </param>
562+
public static float AngleOnAxis(Vector3 self, Vector3 other, Vector3 axis)
563+
{
564+
Vector3 perpendicularSelf = Vector3.Cross(axis, self);
565+
Vector3 perpendicularOther = Vector3.Cross(axis, other);
566+
return Vector3.SignedAngle(perpendicularSelf, perpendicularOther, axis);
567+
}
568+
556569
/// <summary>
557570
/// Truncate float number.
558571
///

Assets/JCSUnity/Scripts/Util/JCS_Random.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,58 @@ public static Vector3 PointInSphere(Vector3 centerPosition, float radius)
138138
Vector3 randomPoint = Random.insideUnitSphere * radius;
139139
return centerPosition + randomPoint;
140140
}
141+
142+
/// <summary>
143+
/// Return a random vector 2 int.
144+
/// </summary>
145+
public static Vector2Int Vector2Int(int min, int max)
146+
{
147+
int x = Range(min, max);
148+
int y = Range(min, max);
149+
return new Vector2Int(x, y);
150+
}
151+
152+
/// <summary>
153+
/// Return a random vector 2.
154+
/// </summary>
155+
public static Vector2 Vector2(float min, float max)
156+
{
157+
float x = Range(min, max);
158+
float y = Range(min, max);
159+
return new Vector2(x, y);
160+
}
161+
162+
/// <summary>
163+
/// Return a random vector 3 int.
164+
/// </summary>
165+
public static Vector3Int Vector3Int(int min, int max)
166+
{
167+
int x = Range(min, max);
168+
int y = Range(min, max);
169+
int z = Range(min, max);
170+
return new Vector3Int(x, y, z);
171+
}
172+
173+
/// <summary>
174+
/// Return a random vector 3.
175+
/// </summary>
176+
public static Vector3 Vector3(float min, float max)
177+
{
178+
float x = Range(min, max);
179+
float y = Range(min, max);
180+
float z = Range(min, max);
181+
return new Vector3(x, y, z);
182+
}
183+
184+
/// <summary>
185+
/// Return a random Quaternion.
186+
/// </summary>
187+
public static Quaternion Quaternion(float min, float max)
188+
{
189+
float x = Range(min, max);
190+
float y = Range(min, max);
191+
float z = Range(min, max);
192+
return UnityEngine.Quaternion.Euler(x, y, z);
193+
}
141194
}
142195
}

0 commit comments

Comments
 (0)