-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPair.cs
More file actions
71 lines (56 loc) · 1.7 KB
/
Pair.cs
File metadata and controls
71 lines (56 loc) · 1.7 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VectorCalculator
{
public class Pair
{
public double Force { get; set; }
public double Angle { get; set; } // in radians
public double XForce { get; set; }
public double YForce { get; set; }
public enum Option {Angle, NoAngle}
public Pair ()
{
}
public Pair(Pair a, Pair b)
:this(a.XForce + b.XForce, a.YForce + b.YForce, Option.NoAngle)
{
}
public Pair( double a, double b, Option o)
{
if (o == Option.Angle)
{
this.Force = a;
this.Angle = Math.PI / 180 * b;
CalculateXYForces();
}
else if(o == Option.NoAngle)
{
this.XForce = a;
this.YForce = b;
this.Force = Math.Sqrt(a * a + b * b);
CalculateAngle();
}
}
private void CalculateAngle()
{
this.Angle = Math.Atan2(this.YForce,this.XForce);
}
private void CalculateXYForces()
{
this.XForce = this.Force * Math.Cos(this.Angle);
this.YForce = this.Force * Math.Sin(this.Angle);
}
public override string ToString()
{
double angleInGrades = this.Angle * 180 / Math.PI;
if (angleInGrades < 0)
angleInGrades += 360;
return "Force: " + Math.Round(this.Force,2).ToString()+ "N" +
" Angle: " + Math.Round(angleInGrades,2).ToString() + "°";
}
}
}