cosine and sine values

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
jpott
Prole
Posts: 8
Joined: Fri May 05, 2017 7:36 pm

cosine and sine values

Post by jpott »

ok I'm missing something obvious, obviously. But I'm sure someone can quickly tell me what the issue is.
this code:

Code: Select all

  angle = 0
  print("angle: "..angle.." cos: "..math.cos(angle).." sin: "..math.sin(angle))
  angle = 90
  print("angle: "..angle.." cos: "..math.cos(angle).." sin: "..math.sin(angle))
  angle = 180
  print("angle: "..angle.." cos: "..math.cos(angle).." sin: "..math.sin(angle))
  
outputs this:
angle: 0 cos: 1 sin: 0
angle: 90 cos: -0.44807361612917 sin: 0.89399666360056
angle: 180 cos: -0.59846006905786 sin: -0.80115263573383

shouldn't it be:
angle: 0 cos: 1 sin: 0
angle: 90 cos: 0 sin: 1
angle: 180 cos: 1 sin: 0
?
drunken_munki
Party member
Posts: 134
Joined: Tue Mar 29, 2011 11:05 pm

Re: cosine and sine values

Post by drunken_munki »

Angles in those functions are in radians.

http://lua-users.org/wiki/MathLibraryTutorial
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: cosine and sine values

Post by zorg »

Code: Select all

a = 0 --math.rad(0)
print(math.cos(a), math.sin(a))
--  1.0,  0.0
a = math.rad(90)
print(math.cos(a), math.sin(a))
--  0.0,  1.0
a = math.rad(180)
print(math.cos(a), math.sin(a))
-- -1.0,  0.0
a = math.rad(270)
print(math.cos(a), math.sin(a))
--  0.0, -1.0
The zeroes might be almost nearly zero though since floating point precision issues may arise.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: cosine and sine values

Post by raidho36 »

Technically those functions do not even work on angles, they take double the area of a unit circle sector as an argument. Because it is a unit circle, its sector area happens to coincide with angle of that sector, by factor of two. Hyperbolic trigonometric functions take double the area of a hyperbola sector.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 5 guests