Skip to content

Commit

Permalink
Added documentation comments + code formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
MAtt5816 committed Apr 14, 2024
1 parent 749baa1 commit 972b198
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 25 deletions.
4 changes: 3 additions & 1 deletion GeometryCalculator/GeometryCalculator.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
<Copyright>Mateusz Szewczyk &lt;MAtt5816&gt;</Copyright>
<PackageLicenseUrl>https://github.com/MAtt5816/geometry-calculator/blob/1.0.0/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/MAtt5816/geometry-calculator</RepositoryUrl>
<PackageTags>calculator;solids;figures;figures-calculator</PackageTags>
<PackageTags>calculator;solids;figures;figures-calculator;ellipsoid;sphere</PackageTags>
<Version>1.0.1</Version>
<Title>GeometryCalculator</Title>
</PropertyGroup>

<ItemGroup>
Expand Down
71 changes: 47 additions & 24 deletions GeometryCalculator/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,72 @@ module Ellipsoid =

module private Area =
module Rotational =
let e a c =
sqrt(1. - a**2. / c**2.)
module General =
let e a c = sqrt (1. - a ** 2. / c ** 2.)

module General =
open FSharp.Stats.Integration

let f psi k =
let integral x = 1. / sqrt(1. - k**2. * sin(x)**2.)
integral |> NumericalIntegration.definiteIntegral(LeftEndpoint, 0., psi, 100)
let e psi k =
let integral x = sqrt(1. - k**2. * sin(x)**2.)
integral |> NumericalIntegration.definiteIntegral(LeftEndpoint, 0., psi, 100)
let integral x =
1. / sqrt (1. - k ** 2. * sin (x) ** 2.)

integral |> NumericalIntegration.definiteIntegral (LeftEndpoint, 0., psi, 100)

let e psi k =
let integral x = sqrt (1. - k ** 2. * sin (x) ** 2.)
integral |> NumericalIntegration.definiteIntegral (LeftEndpoint, 0., psi, 100)

let m a b c =
a**2. * (b**2. - c**2.) / (b**2. * (a**2. - c**2.))
a ** 2. * (b ** 2. - c ** 2.) / (b ** 2. * (a ** 2. - c ** 2.))

let private epsilon a c =
sqrt(1. - (c**2. / a**2.))
let tau a c =
asin(epsilon a c)
let private epsilon a c = sqrt (1. - (c ** 2. / a ** 2.))
let tau a c = asin (epsilon a c)

let sphere r = 4. * Math.PI * r**2.
let sphere r = 4. * Math.PI * r ** 2.

let rotationalEllipsoid c a =
let rotationalEllipsoid c a =
if c < a then
let eValue = Rotational.e c a
2. * Math.PI * a**2. + Math.PI * c**2. / eValue * log((1. + eValue) / (1. - eValue))

2. * Math.PI * a ** 2.
+ Math.PI * c ** 2. / eValue * log ((1. + eValue) / (1. - eValue))
else
let eValue = Rotational.e a c
2. * Math.PI * a**2. * (1. + c / (a * eValue) * asin(eValue))
2. * Math.PI * a ** 2. * (1. + c / (a * eValue) * asin (eValue))

let generalEllipsoid a b c =
let generalEllipsoid a b c =
let tauValue = General.tau a c
let mValue = General.m a b c
2. * Math.PI * (c**2. + (b * c**2.) / sqrt(a**2. - c**2.) * (General.f tauValue mValue) + b * sqrt(a**2. - c**2.) * (General.e tauValue mValue))

2. * Math.PI
* (c ** 2.
+ (b * c ** 2.) / sqrt (a ** 2. - c ** 2.) * (General.f tauValue mValue)
+ b * sqrt (a ** 2. - c ** 2.) * (General.e tauValue mValue))

/// <summary>
/// Function for ellipsoid volume calculation.
/// </summary>
/// <returns>
/// Non-negative <c>double</c> or <c>double.NaN</c> in case at least one negative parameter
/// </returns>
/// <param name="a">a parameter >= 0</param>
/// <param name="b">b parameter >= 0</param>
/// <param name="c">c parameter >= 0</param>
let volume a b c =
if a > 0. && b > 0. && c > 0. then
4. / 3. * Math.PI * a * b * c
else
nan

/// <summary>
/// Function for ellipsoid area calculation.
/// </summary>
/// <returns>
/// Non-negative <c>double</c> if <paramref name="a"/> >= <paramref name="b"/> >= <paramref name="c"/>, else <c>double.NaN</c>
/// </returns>
/// <param name="a">a parameter >= 0</param>
/// <param name="b">b parameter >= 0</param>
/// <param name="c">c parameter >= 0</param>
let area a b c =
if a > 0. && b > 0. && c > 0. then
if a = b && b = c then
Expand All @@ -56,10 +80,9 @@ module Ellipsoid =
Area.rotationalEllipsoid c a
else
Area.rotationalEllipsoid a b
else if a > b && b > c then
Area.generalEllipsoid a b c
else
if a > b && b > c then
Area.generalEllipsoid a b c
else
nan
nan
else
nan
nan

0 comments on commit 972b198

Please # to comment.