8
8
/// </remarks>
9
9
public struct RightTriangleAbstract
10
10
{
11
-
12
- private decimal _lengthA ;
13
- private decimal _angleA ;
14
- private decimal _lengthB ;
15
- private decimal _angleB ;
16
-
17
- private decimal _hypotenuse ;
11
+ /// <summary>
12
+ /// Gets the angle adjacent to side A. Angle is in degrees.
13
+ /// </summary>
14
+ public decimal AngleA { get ; private set ; }
15
+ /// <summary>
16
+ /// Gets the angle adjacent to side B. Angle is in degrees.
17
+ /// </summary>
18
+ public decimal AngleB { get ; private set ; }
19
+ /// <summary>
20
+ /// Gets the length of the hypotenuse.
21
+ /// </summary>
22
+ public decimal Hypotenuse { get ; private set ; }
23
+ /// <summary>
24
+ /// Gets the length of side A.
25
+ /// </summary>
26
+ public decimal LengthA { get ; private set ; }
27
+ /// <summary>
28
+ /// Gets the length of side B.
29
+ /// </summary>
30
+ public decimal LengthB { get ; private set ; }
18
31
19
32
/// <summary>
20
33
/// Creates a right triangle from its two sides.
@@ -23,138 +36,91 @@ public struct RightTriangleAbstract
23
36
/// <param name="lengthB">Length of side B.</param>
24
37
public static RightTriangleAbstract FromTwoSides ( decimal lengthA , decimal lengthB )
25
38
{
26
- var t = default ( RightTriangleAbstract ) ;
27
-
28
- t . _FromTwoSides ( lengthA , lengthB ) ;
29
-
39
+ var t = new RightTriangleAbstract
40
+ {
41
+ LengthA = lengthA ,
42
+ LengthB = lengthB ,
43
+ Hypotenuse = RightTriangle . GetHypFromSides ( lengthA , lengthB ) ,
44
+ AngleA = RightTriangle . GetAngleFromSides ( lengthB , lengthA ) ,
45
+ AngleB = RightTriangle . GetAngleFromSides ( lengthA , lengthB )
46
+ } ;
30
47
return t ;
31
48
}
32
49
33
- private void _FromTwoSides ( decimal lengthA , decimal lengthB )
34
- {
35
- _lengthA = lengthA ;
36
- _lengthB = lengthB ;
37
- _hypotenuse = RightTriangle . GetHypFromSides ( lengthA , lengthB ) ;
38
- _angleA = RightTriangle . GetAngleFromSides ( lengthB , lengthA ) ;
39
- _angleB = RightTriangle . GetAngleFromSides ( lengthA , lengthB ) ;
40
-
41
- }
42
50
/// <summary>
43
51
/// Creates a right triangle from one side and the hypotenuse.
52
+ /// This side is treated as side A.
44
53
/// </summary>
45
54
/// <param name="lengthA">Length of side A.</param>
46
55
/// <param name="hypotenuse">Length of the hypotenuse.</param>
47
- public static object FromSideAHypotenuse ( decimal lengthA , decimal hypotenuse )
56
+ public static RightTriangleAbstract FromSideAHypotenuse ( decimal lengthA , decimal hypotenuse )
48
57
{
49
-
50
- RightTriangleAbstract t = default ( RightTriangleAbstract ) ;
51
-
52
- t . _FromSideAHypotenuse ( lengthA , hypotenuse ) ;
53
-
58
+ var t = new RightTriangleAbstract
59
+ {
60
+ LengthA = lengthA ,
61
+ Hypotenuse = hypotenuse ,
62
+ LengthB = RightTriangle . GetSideFromSideHyp ( lengthA , hypotenuse ) ,
63
+ AngleA = RightTriangle . GetAngleFromAdjSideHyp ( lengthA , hypotenuse ) ,
64
+ AngleB = RightTriangle . GetAngleFromOppSideHyp ( lengthA , hypotenuse )
65
+ } ;
54
66
return t ;
55
-
56
67
}
57
68
58
- private void _FromSideAHypotenuse ( decimal lengthA , decimal hypotenuse )
59
- {
60
- _lengthA = lengthA ;
61
- _hypotenuse = hypotenuse ;
62
- _lengthB = RightTriangle . GetSideFromSideHyp ( lengthA , hypotenuse ) ;
63
- _angleA = RightTriangle . GetAngleFromAdjSideHyp ( lengthA , hypotenuse ) ;
64
- _angleB = RightTriangle . GetAngleFromOppSideHyp ( lengthA , hypotenuse ) ;
65
-
66
- }
67
69
/// <summary>
68
70
/// Creates a right triangle from one side and its adjacent angle in degrees.
71
+ /// This side and angle are treated as side/angle A.
69
72
/// </summary>
70
73
/// <param name="lengthA">Length of side A.</param>
71
74
/// <param name="angleA">Angle adjacent to side A in degrees.</param>
72
- public static object FromSideAAngleA ( decimal lengthA , decimal angleA )
75
+ public static RightTriangleAbstract FromSideAAngleA ( decimal lengthA , decimal angleA )
73
76
{
74
-
75
- RightTriangleAbstract t = default ( RightTriangleAbstract ) ;
76
-
77
- t . _FromSideAAngleA ( lengthA , angleA ) ;
78
-
77
+ var t = new RightTriangleAbstract
78
+ {
79
+ LengthA = lengthA ,
80
+ AngleA = angleA ,
81
+ LengthB = RightTriangle . GetSideFromOppAngleOppSide ( angleA , lengthA ) ,
82
+ AngleB = RightTriangle . GetAngleFromOtherAngle ( angleA ) ,
83
+ Hypotenuse = RightTriangle . GetHypFromSideAdjAngle ( lengthA , angleA )
84
+ } ;
79
85
return t ;
80
-
81
86
}
82
87
83
- private void _FromSideAAngleA ( decimal lengthA , decimal angleA )
84
- {
85
- _lengthA = lengthA ;
86
- _angleA = angleA ;
87
- _lengthB = RightTriangle . GetSideFromOppAngleOppSide ( angleA , lengthA ) ;
88
- _angleB = RightTriangle . GetAngleFromOtherAngle ( angleA ) ;
89
- _hypotenuse = RightTriangle . GetHypFromSideAdjAngle ( lengthA , angleA ) ;
90
-
91
- // tan(A) = LB / LA
92
- // LB = tan(A) * LA
93
- _lengthB = DecimalEx . Tan ( DecimalEx . ToRad ( angleA ) ) * lengthA ;
94
- _angleB = 90m - angleA ;
95
-
96
- // cos(A) = LA / H
97
- // H = LA / cos(A)
98
- _hypotenuse = lengthA / DecimalEx . Cos ( DecimalEx . ToRad ( angleA ) ) ;
99
-
100
- }
101
-
102
- private void _FromSideBAngleB ( decimal lengthB , decimal angleB )
103
- {
104
- _lengthB = lengthB ;
105
- _angleB = angleB ;
106
-
107
- // tan(B) = LA / LB
108
- // LA = tan(B) * LB
109
- _lengthA = DecimalEx . Tan ( DecimalEx . ToRad ( angleB ) ) * lengthB ;
110
- _angleA = 90m - angleB ;
111
-
112
- // cos(B) = LB / H
113
- // H = LB / cos(B)
114
- _hypotenuse = lengthB / DecimalEx . Cos ( angleB ) ;
115
-
116
- }
117
- /// <summary>
118
- /// Gets or sets the angle adjacent to side A. Angle is in degrees.
119
- /// </summary>
120
- public decimal AngleA
121
- {
122
- get { return _angleA ; }
123
- set { _FromSideAAngleA ( _lengthA , value ) ; }
124
- }
125
88
/// <summary>
126
- /// Gets or sets the angle adjacent to side B. Angle is in degrees.
127
- /// </summary>
128
- public decimal AngleB
129
- {
130
- get { return _angleB ; }
131
- set { _FromSideBAngleB ( _lengthB , value ) ; }
132
- }
133
- /// <summary>
134
- /// Gets or sets the length of the hypotenuse.
89
+ /// Creates a right triangle from one side and the hypotenuse.
90
+ /// This side is treated as side B.
135
91
/// </summary>
136
- public decimal Hypotenuse
92
+ /// <param name="lengthA">Length of side B.</param>
93
+ /// <param name="hypotenuse">Length of the hypotenuse.</param>
94
+ public static RightTriangleAbstract FromSideBHypotenuse ( decimal lengthA , decimal hypotenuse )
137
95
{
138
- get { return _hypotenuse ; }
139
- set { _hypotenuse = value ; }
96
+ return FromSideAHypotenuse ( lengthA , hypotenuse ) . SwapSides ( ) ;
140
97
}
98
+
141
99
/// <summary>
142
- /// Gets or sets the length of side A.
100
+ /// Creates a right triangle from one side and its adjacent angle in degrees.
101
+ /// This side and angle are treated as side/angle A.
143
102
/// </summary>
144
- public decimal LengthA
103
+ /// <param name="lengthB">Length of side B.</param>
104
+ /// <param name="angleB">Angle adjacent to side B in degrees.</param>
105
+ public static RightTriangleAbstract FromSideBAngleB ( decimal lengthB , decimal angleB )
145
106
{
146
- get { return _lengthA ; }
147
- set { _FromSideAAngleA ( value , _angleA ) ; }
107
+ return FromSideAAngleA ( lengthB , angleB ) . SwapSides ( ) ;
148
108
}
109
+
149
110
/// <summary>
150
- /// Gets or sets the length of side B.
111
+ /// Swaps which sides / angles are considered A and B.
151
112
/// </summary>
152
- public decimal LengthB
113
+ public RightTriangleAbstract SwapSides ( )
153
114
{
154
- get { return _lengthB ; }
155
- set { _FromSideBAngleB ( value , _angleB ) ; }
115
+ var t = new RightTriangleAbstract
116
+ {
117
+ LengthA = LengthB ,
118
+ AngleA = AngleB ,
119
+ LengthB = LengthA ,
120
+ AngleB = AngleA ,
121
+ Hypotenuse = Hypotenuse ,
122
+ } ;
123
+ return t ;
156
124
}
157
-
158
125
}
159
-
160
- }
126
+ }
0 commit comments