ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Modified ACOS function (https://www.excelbanter.com/excel-discussion-misc-queries/208718-modified-acos-function.html)

danpt

Modified ACOS function
 
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(A20,270,IF(A2<0,90,180)))+D EGREES(ACOS(A2/(A2^2+B2^2)^0.5)),360)"
End Sub

Chip Pearson

Modified ACOS function
 
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)


On Sun, 2 Nov 2008 12:49:01 -0800, danpt
wrote:

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(A20,270,IF(A2<0,90,180)))+ DEGREES(ACOS(A2/(A2^2+B2^2)^0.5)),360)"
End Sub


David Biddulph[_2_]

Modified ACOS function
 
It isn't entirely clear what your formula is trying to do. From 0 to 180
degrees it seems to convert your X and Y into an angle in the correct
quadrant, but beyond 180 degrees it is doing something very different.
I wonder whether =MOD(DEGREES(ATAN2(A2,B2)),360) might be what you are
trying to achieve?
--
David Biddulph

"danpt" wrote in message
...
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(A20,270,IF(A2<0,90,180)))+D EGREES(ACOS(A2/(A2^2+B2^2)^0.5)),360)"
End Sub




danpt

Modified ACOS function
 
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)))


"danpt" wrote:

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(A20,270,IF(A2<0,90,180)))+D EGREES(ACOS(A2/(A2^2+B2^2)^0.5)),360)"
End Sub


David Biddulph[_2_]

Modified ACOS function
 
That looks a lot better, and gives the same result as the much simpler ATAN2
formula which I suggested.
--
David Biddulph

"danpt" wrote in message
...
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)))


"danpt" wrote:

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(A20,270,IF(A2<0,90,180)))+D EGREES(ACOS(A2/(A2^2+B2^2)^0.5)),360)"
End Sub





All times are GMT +1. The time now is 04:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com