[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can anyone help me fix my circle math?



PureBytes Links

Trading Reference Links

>> I am taking the sine of 180* times the index value which is from 0 to
>> 1 instead of taking sine of the angle. This index is a linear
>> function, and 180* this = angle at 0*, 90*, etc. but not in between.
>> Problem is I don't know how to convert the linear index into the
>> appropriate angle. Any ideas? 

Gary answered:
>NewIndex = 1-2*OldIndex  { cos of the angle at that x position }
>Angle = arccos(NewIndex) { the angle }
>Yoffset = sine(Angle)/2
>plot1(Centerprice + Yoffset);
>plot2(Centerprice - Yoffset);
>
>That gets you a lovely circle.  At least in Excel.
>
>Problem:  TS doesn't seem to have arccos.  Maybe it's just too 
>early on a Sunday morning to think that hard, but I can't see how 
>to calculate arccos using arctan or other available functions.  

Here's a good reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vagrpDerivedMath.asp
which says

acos(x) = atan(-x / Sqrt(1 - x*x)) + 2*atan(1)

which is the same as

acos(x) = atan(sqrt(1-x*x)/x) for 0 < x < 1.

Since, for some bizarre reason, the TS trig functions don't use radians
like the rest of the world, you have to resort to a conversion trick:

radtodeg = 180 / 3.14159265358979;
arccos(x) = arctangent(radtodeg*squareroot(1-x*x)/x);

-- 
  ,|___    Alex Matulich -- alex@xxxxxxxxxxxxxx
 // +__>   Director of Research and Development
 //  \ 
 // __)    Unicorn Research Corporation -- http://unicorn.us.com