
Author 
Topic: Some Trig Help (Read 2162 times) 

dlarrivee

Some Trig Help
« on: Apr 17^{th}, 2005, 5:01pm » 

I have a circle that I would like to draw a line from the center of, and make it go out to the edge of the circle, I'd like to be able to draw this line on all 360 degrees, but I'm not sure what to do, maybe someone who is good with trig and can viualize these things can help, here's what I have so far: Code: int x, y, diam, rad; int edgex, edgey; int centerx, centery; void setup() { size(500, 500); diam = 400; rad = diam/2; centerx = width/2; centery = width/2; x = centerx  rad; y = centery  rad; background(255); } void loop() { edgex = centerx; edgey = centery  rad; stroke(0); ellipse(x, y, diam, diam); stroke(255, 0, 0); line(centerx, centery, edgex, edgey); stroke(0); //ellipse(x + 150/2, y + 150/2, diam  150, diam  150); } 





alankilian

Re: Some Trig Help
« Reply #1 on: Apr 17^{th}, 2005, 7:02pm » 

I don't know anything about Java's trig routines, but here is something to get you started. Make a variable "angle" that will count from 0 to 359 edjex = centerx + (cos(angle)*rad) edgey = centery + (sin(angle)*rad) draw from (centerx,contery) to (edgex,edgey) increment the variable angle by 45, 5, or 1 degrees. loop. Now, you will need to figure out of Java's sin and cos routines take a value of degrees or radians. If they take radians, divide your angle by (2*PI) so that you have sin(angle/(2*PI)) etc. Let us know how it works out for you.

« Last Edit: Apr 17^{th}, 2005, 7:03pm by alankilian » 




fry

Re: Some Trig Help
« Reply #2 on: Apr 17^{th}, 2005, 9:47pm » 

actually if you want to convert from degrees, just use: edjex = centerx + (cos(radians(angle))*rad) edgey = centery + (sin(radians(angle))*rad) (sin and cos take radians)




mflux

Re: Some Trig Help
« Reply #3 on: Apr 17^{th}, 2005, 10:30pm » 

Code: edjex = centerx + (cos(radians(angle))*rad) edgey = centery + (sin(radians(angle))*rad) 
 Hey Ben. Correction: Isn't edgey supposed to be edgey = centery  (sin(radians(angle))*rad) since screen units of y counts downwards?




fry

Re: Some Trig Help
« Reply #4 on: Apr 18^{th}, 2005, 1:55am » 

oh, could be.. i was only commenting on the radians() stuff.. didn't look at the code closely.




dlarrivee

Re: Some Trig Help
« Reply #5 on: Apr 18^{th}, 2005, 3:47am » 

Wow, thanks alot. That works quite well!




