Board index » delphi » How To convert COS(n) to an angle? "Simple Maths ??"
BRI MEL
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
|
BRI MEL
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
How To convert COS(n) to an angle? "Simple Maths ??"Hello, Thanks for reading this message. To do with mathematics. Namely TrigONOmetry! For a right angle triangle. COS angle = Adjacent Side / Hypotenuse . ie for a 3,4,5 Triangle... cos (4/5) or cos(0.8) returns 0.69 in radians, And my book tells me to So, How can I write code to return degrees when supplied radians. Thanks again, Brian. |
Osmo Ronkan
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:How To convert COS(n) to an angle? "Simple Maths ??"In article <19971117013801.UAA28...@ladder02.news.aol.com>, QuoteBRI MELLO <brime...@aol.com> wrote: trigonometric functions for that, just multiply the value with (180/pi) Osmo |
BASTAR
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:How To convert COS(n) to an angle? "Simple Maths ??"I'll solve half your question. ArcCos(x) = ArcTan(Sqrt(1 - Sqr(x)) / x); ArcCos is the inverse of Cos etc. As far as converting radians to degrees are concerned, just remember that Now you go write some code! |
Osmo Ronkan
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:How To convert COS(n) to an angle? "Simple Maths ??"In article <01bcf36d$31ba2980$02531...@lexlines.iafrica.com>, QuoteBASTARD <lexli...@iafrica.com> wrote: might solve this for example something like: Function arcsin(x:real):real; forward; Function arcCos(x:real):real; Function ArcSin(x:real):real; This is based on the fact that sin(x)=cos(pi/2-x). The threshold is drawn A simple test for 0 or 1/-1 respectively might also work in most cases. Quote> Tan(x) = Sin(x) / Cos(x); |
BRI MEL
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:How To convert COS(n) to an angle? "Simple Maths ??"In article <64p8ju$...@kruuna.Helsinki.FI>, ronka...@cc.helsinki.fi (Osmo QuoteRonkanen) writes: Using the example I gave ie Cos(0.8) returning 0.69 radians... Unfortunately this differs from my text book example. ie 0.8 inverse cos = 36.9 degrees a full 3 degrees difference! Brian. |
Horst Kraem
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:How To convert COS(n) to an angle? "Simple Maths ??"On 17 Nov 1997 20:37:22 +0200, ronka...@cc.helsinki.fi (Osmo Ronkanen) Quote>Note that the two above fail at (or close to) 0 and 1 respectively. One possible because the optimal threshold depends on the implementation of the floating point data type. Here it is easy to avoid it by force using a little bit of trigonometry. {$N+} function arccos(c:float):float; Quote} val:float; begin val:=2*arctan(sqrt((1-abs(c))/(1+abs(c)))); if c<0 then val:=pi-val; arccos:=val end; function arcsin(s:float):float; Quote} val:float; begin val:=pi/2-2*arctan(sqrt((1-abs(s))/(1+abs(s)))); if s<0 then val:=-val; arcsin:=val end; function atan2(y,x:float):float; For compatibility with other programming -pi < atan2 <= pi Hint: In order to compute the oriented rotation angle phi = atan2(x1*y2-y1*x2,x1*x2+y1*y2) { *180/pi }; Quote} val:float; begin val:=2*arctan(abs(y)/(sqrt(sqr(y)+sqr(x))+abs(x))); if x<0 then val:=pi-val; if y<0 then val:=-val; atan2:=val end; A more pedestrian and still safe implementation avoiding overflows function arcsin(s:float):float; function arccos(c:float):float; or just function arccos(c:float):float; If x compares FALSE to +-1 then abs(x)=1-delta and delta is not less Regards |
Osmo Ronkan
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:How To convert COS(n) to an angle? "Simple Maths ??"In article <19971118123400.HAA01...@ladder02.news.aol.com>, QuoteBRI MELLO <brime...@aol.com> wrote: cosine is just a value. Quote>0.69 * (180/pi) = 39.92 degrees between radians and degrees. Just multiply by (180/pi). 0.8*180/pi= 45.84 degrees. Now what on earth do you want to achieve? Osmo |
BRI MEL
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:How To convert COS(n) to an angle? "Simple Maths ??"In article <01bcf36d$31ba2980$02531...@lexlines.iafrica.com>, "BASTARD" Quote<lexli...@iafrica.com> writes: 0.8 returning 36.9 deg on a calculator, and applied the above formula to TP3's Cos function, which did not. I am still confused about this but relived to say that tp3 ArcTan (opp/adj) works perfectly with the above formula. That is.. Angle := 180 * ArcTan(opp/adj)/pi { Returned 36.9 degrees! } However... Angle := 180 * Cos(adj/hyp)/ Pi ; { Returned 39.?? degrees } Why one works and the other not is beyond me. I am grateful to all, for your Peace! Brian. |
Osmo Ronkan
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:How To convert COS(n) to an angle? "Simple Maths ??"In article <19971121020900.VAA19...@ladder02.news.aol.com>, QuoteBRI MELLO <brime...@aol.com> wrote: Cos(36.9*pi/180) = 0.8 = adj/hyp As I said before the result of cosine is not in radians. It is just a If you want ArcCos you may try following: function ArcSin(x:real):real; function ArcCos(x:real):real; Try those and you will get 36.86990 Quote
|