Need help with code snippet using trig.
BlitzMax Forums/BlitzMax Programming/Need help with code snippet using trig.| 
 | ||
| I downloaded this code from the net that draws a circle using the sine and cosine functions, but I can't figure out what I'm doing wrong in Max. Code I converted to Max: And here is the code written in C using Allegro: | 
| 
 | ||
| Different example, although I believe you're looking for the same thing: Const Radius:Int = 100 Const Step_Angle:Float = 2.0 Const ScreenWidth:Int = 800 Const ScreenHeight:Int = 600 Global Angle:Int = 0 Graphics ScreenWidth,ScreenHeight SetColor 255, 255, 255 Cls While angle < 360 Local X:Int = (ScreenWidth * 0.5) + (Radius * Sin(angle)) Local Y:Int = (ScreenHeight * 0.5) + (Radius * Cos(angle)) Plot(x,y) Angle:+Step_Angle Wend Flip WaitKey Edit: If this is your first time getting into small trig, you're probobly just about to hit a time in coding that starts to really get fun, especially when messing around with fractal stuff. And even understanding this small bit will get you through a LOT of 3d formulas. Good luck. | 
| 
 | ||
| Remember that BlitzMax works in Degrees, and your example expects Radians... :-) | 
| 
 | ||
| @Retimer Yeah, I'm really looking forward to using math routines instead of writing hacks. I figure its about time. I wish I would have started 10-15 years ago though. @Brucey Ah...thanks! It's working now! | 
| 
 | ||
| And just as an aside, what you're doing there has nothing to do with trigonometry. | 
| 
 | ||
| @Rob Farley I thought the sine and cosine functions were trigonometry functions. | 
| 
 | ||
|  I thought the sine and cosine functions were trigonometry functions.  http://en.wikipedia.org/wiki/Trigonometry win. | 
| 
 | ||
| I'm not sure who's winning what but Sine and Cosine functions are used in Trigonometry, however, Sine and Cosine functions do not equal trigonometry. | 
| 
 | ||
| sine and cosine are two of the three primary trigonometric functions. This thread (and the code) are entirely about trigonometry. That said, I've been coding a bunch of vector object transformations this way and I really enjoyed stick-building the math code and re-aquainting myself with basic high-school and undergrad math. -pmc | 
| 
 | ||
| And trigonometry deals with triangles.  And how do you draw a circle on a computer screen?  By calculating lots and lots of triangles.  One for each pixel in fact. Each pixel in a circle is one point of a right triangle, where the point's radius is the length of the hypoteneuse, the point's X coordinate is the length of the opposite side, and the point's Y coordinate is the length of the adjacent side. Trigonometry! Ta da! |