Area Calculations Library: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Area Calculations Library
| Old | New | Line | |
|---|---|---|---|
| 1 | + | A library for area calculation. | |
| 2 | + | ||
| 3 | + | ``` pascal | |
| 4 | + | unit uArea ; | |
| 5 | + | ||
| 6 | + | {$mode objfpc} {$H +} | |
| 7 | + | {$IMPLICITEXCEPTIONS OFF} | |
| 8 | + | ||
| 9 | + | interface | |
| 10 | + | ||
| 11 | + | uses | |
| 12 | + | SysUtils ; | |
| 13 | + | ||
| 14 | + | function funSquareArea (dblL : double) : double; | |
| 15 | + | function funSquareDiagonalLength (dblL : double) : double; | |
| 16 | + | function funSquareLength (dblA : double) : double; | |
| 17 | + | function funSquarePerimeter (dblL : double) : double; | |
| 18 | + | ||
| 19 | + | function funRectangleArea (dblL, dblB : double) : double; | |
| 20 | + | function funRectangleDiagonalLength (dblL, dblB : double) : double; | |
| 21 | + | function funRectanglePerimeter (dblL, dblB : double) : double; | |
| 22 | + | ||
| 23 | + | function funRhombusArea (dblL, dblB : double) : double; | |
| 24 | + | function funRhombusPerimeter (dblL, dblB : double) : double; | |
| 25 | + | ||
| 26 | + | function funeTrapezoidArea (dblL1, dblL2, dblB : double) : double; | |
| 27 | + | function funTrapezMedian (dblL1, dblL2 : double) : double; | |
| 28 | + | function funTrapezoidPerimeter (dblL1, dblL2, dblL3, dblL4 : double) : double; | |
| 29 | + | ||
| 30 | + | function funTriangleArea (dblL, dblB : double) : double; | |
| 31 | + | function funTrianglePerimeter (dblL1, dblL2, dblL3 : double) : double; | |
| 32 | + | ||
| 33 | + | function funEquilateralTriangleHeight (dblL : double) : double; | |
| 34 | + | ||
| 35 | + | function funCircleArea (dblD : double) : double; | |
| 36 | + | function funCircleCircumference (dblD : double) : double; | |
| 37 | + | function funCircleRadius (dblA : double) : double; | |
| 38 | + | ||
| 39 | + | function funCircleSegmentArea (dblA, dblD : double) : double; | |
| 40 | + | function funCircleSegmentChordLength (dblR, dblA : double) : double; | |
| 41 | + | ||
| 42 | + | function funCircleSegmentArcLength (dblR, dblA : double) : double; | |
| 43 | + | function funCircleSegmentChordLength (dblR, dblB : double) : double; | |
| 44 | + | ||
| 45 | + | function funCircleSegmentSagitta (dblR, dblL : double) : double; | |
| 46 | + | ||
| 47 | + | function funEllipseArea (dblD1, dblD2 : double) : double; | |
| 48 | + | function funEllipseCircumference (dblD1, dblD2 : double) : double; | |
| 49 | + | ||
| 50 | + | implementation | |
| 51 | + | ||
| 52 | + | function funSquareArea (dblL : double) : double; | |
| 53 | + | begin | |
| 54 | + | // dblL is the length | |
| 55 | + | Result := dblL * dblL; | |
| 56 | + | end; | |
| 57 | + | ||
| 58 | + | function funSquareDiagonalLength (dblL : double) : double; | |
| 59 | + | begin | |
| 60 | + | // dblL is the length | |
| 61 | + | Result := (sqrt (2)) * dblL; | |
| 62 | + | end; | |
| 63 | + | ||
| 64 | + | function funSquareLength (dblA : double) : double; | |
| 65 | + | begin | |
| 66 | + | // dblA is the area | |
| 67 | + | Result := sqrt (dblA); | |
| 68 | + | end; | |
| 69 | + | ||
| 70 | + | function SquarePerimeter (dblL : double) : double; | |
| 71 | + | begin | |
| 72 | + | // dblL is the length | |
| 73 | + | Result := 4 * dblL; | |
| 74 | + | end; | |
| 75 | + | ||
| 76 | + | function funRectangleArea (dblL, dblB : double) : double; | |
| 77 | + | begin | |
| 78 | + | // dblL is the length | |
| 79 | + | // dblB is the width | |
| 80 | + | Result := dblL * dblB; | |
| 81 | + | end; | |
| 82 | + | ||
| 83 | + | function funRectangleDiagonalLength (dblL, dblB : double) : double; | |
| 84 | + | begin | |
| 85 | + | // dblL is the length | |
| 86 | + | // dblB is the width | |
| 87 | + | Result := sqrt (dblL + dblB); | |
| 88 | + | end; | |
| 89 | + | ||
| 90 | + | function funRectanglePerimeter (dblL, dblB : double) : double; | |
| 91 | + | begin | |
| 92 | + | // dblL is the length | |
| 93 | + | // dblB is the width | |
| 94 | + | Result := 2 * (dblL + dblB); | |
| 95 | + | end; | |
| 96 | + | ||
| 97 | + | function funRhombusArea (dblL, dblB : double) : double; | |
| 98 | + | begin | |
| 99 | + | // rhombus = parallelogram | |
| 100 | + | // dblL is the length | |
| 101 | + | // dblB is the width | |
| 102 | + | Result := dblL * dblB; | |
| 103 | + | end; | |
| 104 | + | ||
| 105 | + | function funRhombusPerimeter (dblL, dblB : double) : double; | |
| 106 | + | begin | |
| 107 | + | // rhombus = parallelogram | |
| 108 | + | // dblL is the length | |
| 109 | + | // dblB is the width | |
| 110 | + | Result := 2 * (dblL + dblB); | |
| 111 | + | end; | |
| 112 | + | ||
| 113 | + | function funTrapezoidArea (dblL1, dblL2, dblB : double) : double; | |
| 114 | + | begin | |
| 115 | + | // dblL1 is the great length | |
| 116 | + | // dblL2 is the short length | |
| 117 | + | // dblB is the width | |
| 118 | + | Result := ((dblL1 * dblL2) / 2) * dblB; | |
| 119 | + | end; | |
| 120 | + | ||
| 121 | + | function funTrapezoidMedian (dblL1, dblL2 : double) : double; | |
| 122 | + | begin | |
| 123 | + | // dblL1 is the large length | |
| 124 | + | // dblL2 is the small length | |
| 125 | + | Result := (dblL1 * dblL2) / 2; | |
| 126 | + | end; | |
| 127 | + | ||
| 128 | + | function funTrapezoidPerimeter (dblL1, dblL2, dblL3, dblL4 : double) : double; | |
| 129 | + | begin | |
| 130 | + | // dblL1 to dblL4 are the lengths of the trapezoid | |
| 131 | + | Result := dblL1 + dblL2 + dblL3 + dblL4; | |
| 132 | + | end; | |
| 133 | + | ||
| 134 | + | function funTriangleArea (dblL, dblB : double) : double; | |
| 135 | + | begin | |
| 136 | + | // dblL is the length | |
| 137 | + | // dblB is the width | |
| 138 | + | Result := (dblL * dblB) / 2; | |
| 139 | + | end; | |
| 140 | + | ||
| 141 | + | function funTrianglePerimeter (dblL1, dblL2, dblL3 : double) : double; | |
| 142 | + | begin | |
| 143 | + | // dblL1 to dblL3 are the lengths of the triangle | |
| 144 | + | Result := dblL1 + dblL2 + dblL3; | |
| 145 | + | end; | |
| 146 | + | ||
| 147 | + | function funEquilateralTriangleHeight (dblL : double) : double; | |
| 148 | + | begin | |
| 149 | + | // dblL is the length | |
| 150 | + | Result := 0.5 * sqrt(3) * dblL; | |
| 151 | + | end; | |
| 152 | + | ||
| 153 | + | function funCircleArea (dblD : double) : double; | |
| 154 | + | begin | |
| 155 | + | // dblD is the diameter | |
| 156 | + | Result := (PI * (dblD * dblD)) / 4; | |
| 157 | + | end; | |
| 158 | + | ||
| 159 | + | function funCircleCircumference (dblD : double) : double; | |
| 160 | + | begin | |
| 161 | + | // dblD is the diameter | |
| 162 | + | Result := PI * dblD; | |
| 163 | + | end; | |
| 164 | + | ||
| 165 | + | function funCircleRadius (dblA : double) : double; | |
| 166 | + | begin | |
| 167 | + | // dblA is the area | |
| 168 | + | Result := sqrt (dblA / PI); | |
| 169 | + | end; | |
| 170 | + | ||
| 171 | + | function funCircleSegmentArea (dblA, dblD : double) : double; | |
| 172 | + | begin | |
| 173 | + | // dblD is the circle diameter | |
| 174 | + | // dblA is the central angle | |
| 175 | + | Result := (PI * (dblD * dblD) / 4) * (dblA / 360); | |
| 176 | + | end; | |
| 177 | + | ||
| 178 | + | function funCircleSegmentChordLength (dblR, dblA : double) : double; | |
| 179 | + | begin | |
| 180 | + | // dblR is the radius | |
| 181 | + | // dblA is the central angle | |
| 182 | + | Result := 2 * (dblR * (sin (dblA / 2))); | |
| 183 | + | end; | |
| 184 | + | ||
| 185 | + | function funCircleSegmentArcLength (dblR, dblA : double) : double; | |
| 186 | + | begin | |
| 187 | + | // dblR is the radius | |
| 188 | + | // dblA is the central angle | |
| 189 | + | Result := (PI * dblR * dblA) / 180; | |
| 190 | + | end; | |
| 191 | + | ||
| 192 | + | function funCircleSegmentChordLength (dblR, dblB : double) : double; | |
| 193 | + | begin | |
| 194 | + | // dblR is the radius | |
| 195 | + | // dblB is the width | |
| 196 | + | Result := 2 * sqrt (dblB * ((2 * dblR) - dblB)); | |
| 197 | + | end; | |
| 198 | + | ||
| 199 | + | function funCircleSegmentSagitta (dblR, dblL : double) : double; | |
| 200 | + | begin | |
| 201 | + | // dblR is the radius | |
| 202 | + | // dblL is the chord length | |
| 203 | + | Result := dblR - (sqrt ((dblR * dblR) - ((dblL * dblL) / 4))); | |
| 204 | + | end; | |
| 205 | + | ||
| 206 | + | function funEllipseArea (dblD1, dblD2 : double) : double; | |
| 207 | + | begin | |
| 208 | + | // dblD1 is the large diameter of the ellipse | |
| 209 | + | // dblD2 is the small diameter of the ellipse | |
| 210 | + | Result := (Pi * dblD1 * dblD2) / 4; | |
| 211 | + | end; | |
| 212 | + | ||
| 213 | + | function funEllipseCircumference (dblD1, dblD2 : double) : double; | |
| 214 | + | begin | |
| 215 | + | // dblD1 is the large diameter of the ellipse | |
| 216 | + | // dblD2 is the small diameter of the ellipse | |
| 217 | + | Result := (Pi / 2) * (dblD1 + dblD2); | |
| 218 | + | end; | |
| 219 | + | ||
| 220 | + | end. | |
| 221 | + | ``` | |
| 222 | + | ||
| 223 | + | --- | |
| 224 | + | *From the Free Pascal wiki, page "Area Calculations Library", as it stood on 2020-08-09 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
