This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Utils.cs
68 lines (62 loc) · 2.43 KB
/
Utils.cs
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
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GesturalMusic
{
class Utils
{
/// <summary>
/// Clamps the value between the min and max
/// </summary>
/// <param name="min">The min to clamp to.</param>
/// <param name="max">The max to clamp to.</param>
/// <param name="value">The value to clamp.</param>
/// <returns>The value clamped. If the value is less than the minimum, it will return the minimum.
/// If the value is greater than the maximum, it will return the maximum.</returns>
public static float Clamp(float min, float max, float value)
{
return (value < min) ? min : (value > max) ? max : value;
}
/// <summary>
/// Clamps the value between the min and max
/// </summary>
/// <param name="min">The min to clamp to.</param>
/// <param name="max">The max to clamp to.</param>
/// <param name="value">The value to clamp.</param>
/// <returns>The value clamped. If the value is less than the minimum, it will return the minimum.
/// If the value is greater than the maximum, it will return the maximum.</returns>
public static float Clamp(int min, int max, int value)
{
return (value < min) ? min : (value > max) ? max : value;
}
public static float LengthFloat(Joint p1, Joint p2)
{
return (float)Math.Sqrt(
Math.Pow(p1.Position.X - p2.Position.X, 2) +
Math.Pow(p1.Position.Y - p2.Position.Y, 2) +
Math.Pow(p1.Position.Z - p2.Position.Z, 2));
}
public static float LengthFloat(DepthSpacePoint p1, DepthSpacePoint p2)
{
return (float)Math.Sqrt(
Math.Pow(p1.X - p2.X, 2) +
Math.Pow(p1.Y - p2.Y, 2));
}
public static double Length(Joint p1, Joint p2)
{
return Math.Sqrt(
Math.Pow(p1.Position.X - p2.Position.X, 2) +
Math.Pow(p1.Position.Y - p2.Position.Y, 2) +
Math.Pow(p1.Position.Z - p2.Position.Z, 2));
}
public static double Length(DepthSpacePoint p1, DepthSpacePoint p2)
{
return Math.Sqrt(
Math.Pow(p1.X - p2.X, 2) +
Math.Pow(p1.Y - p2.Y, 2));
}
}
}