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 \f$hypotenuse = \sqrt{ leg_1^{(2)} + leg_2^{(2)} }\f$
23  * where \f$leg_1\f$ and \f$leg_2\f$ are two sides of a triangle which form a
24  * 90° angle.
25  *
26  * @see #calculateHypotenuse
27  * @see #calculateLeg
28  */
29 public final class Pythagoras implements Base {
30 
31  /**
32  * Hidden constructor for utility class.
33  */
34  private Pythagoras() {
35 
36  throw new IllegalStateException("do not instantiate utilit classes");
37 
38  }
39 
40  // ! [Calculate the Hypotenuse]
41 
42  /**
43  * Calculate the hypotenuse of a right triangle whose legs are of lengths
44  * `a` and `b`.
45  *
46  * This returns \f$\sqrt{ leg_{1}^{(2)} + leg_{2}^{(2)} }\f$
47  *
48  * @param leg1
49  * One leg's length
50  *
51  * @param leg2
52  * The other leg's length
53  *
54  * @return The hypotenuse
55  *
56  * @throws IllegalArgumentException
57  * Thrown if either `a` or `b` is less than or equal to 0.0
58  */
59  public static double calculateHypotenuse(final double leg1, final double leg2) {
60 
61  if (leg1 <= 0.0) {
62 
63  throw new IllegalArgumentException("a must be positive");
64 
65  }
66 
67  if (leg2 <= 0.0) {
68 
69  throw new IllegalArgumentException("b must be positive");
70 
71  }
72 
73  return Math.sqrt(leg1 * leg1 + leg2 * leg2);
74 
75  }
76 
77  // ! [Calculate the Hypotenuse]
78 
79  // ! [Calculate the Other Leg]
80 
81  /**
82  * Calculate the length of the remaining leg of a right triangle given the
83  * length of one leg and its hypotenuse.
84  *
85  * This returns \f$\sqrt{ hypotenuse^2 - leg^2 }\f$
86  *
87  * @param leg
88  * One leg's length
89  *
90  * @param hypotenuse
91  * The length of the hypotenuse
92  *
93  * @return The length of the other leg
94  *
95  * @throws IllegalArgumentException
96  * Thrown if either `l` is less than or equal to 0.0 or `h` is
97  * than or equal to `l`
98  */
99  public static double calculateLeg(final double leg, final double hypotenuse) {
100 
101  if (leg <= 0.0) {
102 
103  throw new IllegalArgumentException("l must be positive");
104 
105  }
106 
107  if (hypotenuse <= leg) {
108 
109  throw new IllegalArgumentException("h must be greater than l");
110 
111  }
112 
113  return Math.sqrt(hypotenuse * hypotenuse - leg * leg);
114 
115  }
116 
117  // ! [Calculate the Other Leg]
118 
119 }
Pythagoras()
Hidden constructor for utility class.
Definition: Pythagoras.java:34
static double calculateHypotenuse(final double leg1, final double leg2)
Calculate the hypotenuse of a right triangle whose legs are of lengths a and b.
Definition: Pythagoras.java:59
A mock interface used to demonstrate Doxygen features.
Definition: Base.java:22
Permutations of the Pythagorean theorem.
Definition: Pythagoras.java:29
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...
Definition: Pythagoras.java:99