Two Pi radians.
The Java trigonometric functions
are static methods of the Math
.
They
take radians for their arguments
(as do such functions in most programming languages).
Here is the complete method:
private void drawStar( int x, int y, int size ) { int endX, endY ; // Six lines radiating from (x,y) for ( int i = 0; i<6; i++ ) { endX = x + (int)(size*Math.cos( (2*Math.PI/6)*i )); endY = y - (int)(size*Math.sin( (2*Math.PI/6)*i )); // Note "-" graph.drawLine( x, y, endX, endY ); } }
The circle is divided into six pieces.
The constant pi is available in Java as Math.PI
(2*Math.PI/6)
You could do the division and write this as (Math.PI/3)
The "-" sign is used for endY
because
y
increases in value going down.
Using a "+" would also work because of symmetry.