Kirk Rader  1.0-SNAPSHOT
Pythagoras.java
Go to the documentation of this file.
1 /*
2  * Copyright 2016 Kirk Rader
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package us.rader.usingdoxygen;
18 
19 /**
20  * Permutations of the Pythagorean theorem.
21  *
22  * The basic theorem is:
23  *
24  * \f[
25  * a = \sqrt{ b^2 + c^2 }
26  * \f]
27  *
28  * where \f$a\f$ is the hypotenuse of a right triangle and \f$b\f$, \f$c\f$ are
29  * its legs (the sides which form a 90° angle).
30  *
31  * @see #calculateHypotenuse
32  * @see #calculateLeg
33  */
34 public final class Pythagoras implements Base {
35 
36  /**
37  * Hidden constructor for utility class.
38  */
39  private Pythagoras() {
40 
41  throw new IllegalStateException("do not instantiate utilit classes");
42 
43  }
44 
45  // ! [Calculate the Hypotenuse]
46 
47  /**
48  * Calculate the hypotenuse of a right triangle whose legs are of lengths
49  * `leg1` and `leg2`.
50  *
51  * This returns \f$\sqrt{ b^2 + c^2 }\f$ where \f$a\f$ is `b` and \f$c\f$ is
52  * `b`.
53  *
54  * @param leg1
55  * One leg's length
56  *
57  * @param leg2
58  * The other leg's length
59  *
60  * @return The hypotenuse
61  *
62  * @throws IllegalArgumentException
63  * Thrown if either `leg1` or `leg2` is less than or equal to 0.0
64  */
65  public static double calculateHypotenuse(final double leg1, final double leg2) {
66 
67  if (leg1 <= 0.0) {
68 
69  throw new IllegalArgumentException("a must be positive");
70 
71  }
72 
73  if (leg2 <= 0.0) {
74 
75  throw new IllegalArgumentException("b must be positive");
76 
77  }
78 
79  return Math.sqrt(leg1 * leg1 + leg2 * leg2);
80 
81  }
82 
83  // ! [Calculate the Hypotenuse]
84 
85  // ! [Calculate the Other Leg]
86 
87  /**
88  * Calculate the length of the remaining leg of a right triangle given the
89  * length of one leg and its hypotenuse.
90  *
91  * This returns \f$\sqrt{ a^2 - b^2 }\f$ where \f$a\f$ is `hypotenuse` and
92  * \f$b\f$ is `b`.
93  *
94  * @param leg
95  * One leg's length
96  *
97  * @param hypotenuse
98  * The length of the hypotenuse
99  *
100  * @return The length of the other leg
101  *
102  * @throws IllegalArgumentException
103  * Thrown if either `leg` is less than or equal to 0.0 or
104  * `hypotenuse` is than or equal to `leg`
105  */
106  public static double calculateLeg(final double leg,
107  final double hypotenuse) {
108 
109  if (leg <= 0.0) {
110 
111  throw new IllegalArgumentException("l must be positive");
112 
113  }
114 
115  if (hypotenuse <= leg) {
116 
117  throw new IllegalArgumentException("h must be greater than l");
118 
119  }
120 
121  return Math.sqrt(hypotenuse * hypotenuse - leg * leg);
122 
123  }
124 
125  // ! [Calculate the Other Leg]
126 
127 }
Pythagoras()
Hidden constructor for utility class.
Definition: Pythagoras.java:39
static double calculateHypotenuse(final double leg1, final double leg2)
Calculate the hypotenuse of a right triangle whose legs are of lengths leg1 and leg2.
Definition: Pythagoras.java:65
A mock interface used to demonstrate Doxygen features.
Definition: Base.java:22
Permutations of the Pythagorean theorem.
Definition: Pythagoras.java:34
static double calculateLeg(final double leg, final double hypotenuse)
Calculate the length of the remaining leg of a right triangle given the length of one leg and its hyp...