Modified ACOS function

D

danpt

I want to modified ACOS function to display in degrees reflecting to its
quartrant.
Is there another simpler formula to replace then one I have in cell(D2)?
Sub worksample()
Range("A1") = "X"
Range("B1") = "Y"
Range("C1") = "deg"
Range("D1") = "mod. ACOS"
Range("A2") = -1
Range("B2") = -1
Range("C2") = "=DEGREES(ACOS(A2/(A2^2+B2^2)^0.5))"
Range("D2") =
"=MOD(IF(B2>=0,360,IF(A2>0,270,IF(A2<0,90,180)))+DEGREES(ACOS(A2/(A2^2+B2^2)^0.5)),360)"
End Sub
 
C

Chip Pearson

The following code will do what you want:

Function DegreesToRadians(Degrees As Double) As Double
Const PI As Double = 3.14159265358979
DegreesToRadians = (Degrees / 360) * 2 * PI
End Function
Function RadiansToDegrees(Radians As Double) As Double
Const PI As Double = 3.14159265358979
RadiansToDegrees = 360 * Radians / (2 * PI)
End Function
Function Quadrant(Radians As Double) As Integer
Dim D As Double
D = RadiansToDegrees(Radians)
Select Case D
Case 0 To 90
Quadrant = 1
Case 91 To 180
Quadrant = 2
Case 181 To 270
Quadrant = 3
Case Else
Quadrant = 4
End Select
End Function

The DegreesToRadians function converts a number of degrees to its
radians equivalent. The RadiansToDegrees function converts radians to
degrees. The Quadrant function returns the quadrant (90 degrees
regions, starting at the X axis rotating counter-clockwise), of a
value in Radians.

If you want to compute the quadrant of a value in degrees with a
worksheet function, use

=VLOOKUP(B3,{0,1;90,2;180,3;270,4},2,TRUE)

where B3 is the value in degrees. Pay attention to the mix of commas
and semi-colons in the formula.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
D

danpt

Thank you Chip,
Thank you David,
I overlooked my formulation, cell(D2) should look like
=IF(B2<0,360-DEGREES(ACOS(A2/(A2^2+B2^2)^0.5)),DEGREES(ACOS(A2/(A2^2+B2^2)^0.5)))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top