FWIW I get 7.something also
Couple issues with the original macro
1. Input is QuadrantRadius, bur RadiusQuadrant is used ( = 0)
2. RadiusQuadand is Set, but it's not an Object
3. HalfCircleRadius does not need to be passed
Function CalculateQuadrantRemainingArea(QuadrantRadius As Double, HalfCircle1Radius As Double) As Double
' Calculates the remaining area of a quadrant with two non-overlapping half-circles.
' Half-circle 1 (HC1) is on the horizontal leg from the origin.
' Half-circle 2 (HC2) is on the vertical leg from the top of the quadrant.
Const PI As Double = 3.14159265358979 ' Using a more precise PI value
Dim AreaQuadrant As Double
Dim AreaHC1 As Double
Dim AreaHC2 As Double
Dim RadiusQuadrant As Double
Dim RadiusHC1 As Double
Dim RadiusHC2 As Double
Dim RemainingArea As Double
Set RadiusQuadrant = 6
Set RadiusHC1 = 3
' Input validation (optional but recommended)
If QuadrantRadius <= 0 Or HalfCircle1Radius <= 0 Then
CalculateQuadrantRemainingArea = CVErr(xlErrValue) ' Return #VALUE! error for invalid input
Exit Function
End If
If HalfCircle1Radius > QuadrantRadius / 2 Then
' This scenario implies HC1 diameter is larger than the quadrant radius
' or it cannot fit fully on the leg from the origin.
CalculateQuadrantRemainingArea = CVErr(xlErrValue) ' Indicate an impossible scenario
Exit Function
End If
' Step 1: Calculate the area of the quadrant
AreaQuadrant = (1 / 4) * PI * (RadiusQuadrant ^ 2)
My version
Option Explicit
' Calculates the remaining area of a quadrant with two non-overlapping half-circles.
' Half-circle 1 (HC1) is on the horizontal leg from the origin.
' Half-circle 2 (HC2) is on the vertical leg from the top of the quadrant.
Function CalculateQuadrantRemainingArea(QuadrantRadius As Double) As Variant
Const PI As Double = 3.14159265358979 ' Using a more precise PI value
Dim AreaQuadrant As Double
Dim AreaHC1 As Double
Dim AreaHC2 As Double
Dim RadiusHC1 As Double
Dim RadiusHC2 As Double
Dim RemainingArea As Double
' Step 1: Calculate the area of the quadrant
AreaQuadrant = PI * (QuadrantRadius ^ 2) / 4
' Step 2: Calculate the area of the first half-circle (HC1)
' Assuming its diameter spans 2 * HalfCircle1Radius along the leg.
RadiusHC1 = QuadrantRadius / 2
AreaHC1 = PI * (RadiusHC1 ^ 2) / 2
' Step 3: Determine the radius of the second half-circle (HC2)
' Using the non-overlapping (tangency) condition
' (r2^2 - 12r2 + 45 = 9 + 6r2 + r2^2) simplifies to 36 = 18r2 --> r2 = 2
' In the general case, where C1=(r1,0) and C2=(0,R-r2), we solve:
' Sqrt(r1^2 + (R-r2)^2) = r1 + r2
' r1^2 + (R-r2)^2 = (r1+r2)^2
' r1^2 + R^2 - 2*R*r2 + r2^2 = r1^2 + 2*r1*r2 + r2^2
' R^2 - 2*R*r2 = 2*r1*r2
' R^2 = 2*R*r2 + 2*r1*r2
' R^2 = r2 * (2R + 2r1)
' r2 = R^2 / (2 * (R + r1))
RadiusHC2 = (QuadrantRadius ^ 2) / (2 * (QuadrantRadius + RadiusHC1))
' Step 4: Calculate the area of the second half-circle (HC2)
AreaHC2 = PI * (RadiusHC2 ^ 2) / 2
' Step 5: Calculate the Remaining Area
RemainingArea = AreaQuadrant - AreaHC1 - AreaHC2
CalculateQuadrantRemainingArea = RemainingArea
End Function