I cant give you the rest of the code as it is a compiled class, i dont know it

myself, only given instructions.... but this is the working code...however,

I've discovered it only completes circles which have sides that are a factor of

360:

double angle = 360 / nSteps;

double pi = Math.PI;

angle = Math.toRadians(angle);

double newx, newy, oldx = x + r, oldy = y;

for(int i = 0; i <= nSteps; i++) {

newx = (r * Math.cos(angle*i)) + x;

newy = (r * Math.sin(angle*i)) + y;

da.line(oldx,oldy,newx,newy);

oldx = newx;

oldy = newy;

}

Jen x

Yes, of course. Think about it. You are drawing circle segments, or, one

might say, triangles whose apexes are located at the center of the circle.

To say it yet another way, you are constructing polygons. There must be an

integral number of triangles (or polygon sides if you prefer), and that

integer must be a factor of 360.

It isn't as though 360 has a shortage of divisors to choose from:

1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20,

24, 30, 36, 40, 45, 60, 72, 90, 120, 180, 360.

Kind of astonishing, when you think about it. There are very few integers

that have this large a ratio : "divisors of (n) / n".

Also, you need to think of a better way to set the initial value for the

oldx, oldy values. That is part of the problem.

Why not set oldx and oldy to newx and newy for the first drawing of the

circle, *before* calling the line drawing routine?

if(i == 0) {

oldx = newx;

oldy = newy;

}

// draw the circle segment here

This assures that the circle doesn't have any attached, seemingly random

lines.

--

Paul Lutus

http://www.yqcomputer.com/

DONE IT - FOR REAL THIS TIME!!!!

Final coding......

double angle = 360.0 / nSteps;

double oldx = x + r, oldy = y, newx, newy;

for(double i = angle; i <= 360 + angle; i += angle){

newx = r * Math.cos(Math.toRadians(i)) + x;

newy = r * Math.sin(Math.toRadians(i)) + y;

da.line(oldx, oldy, newx, newy);

oldx = newx;

oldy = newy;

}

Small problem... but annoying!!!!!

Thanks for the help Paul. Much appreciated.....

Handing in tomorrow......

Jenski xxx

Final coding......

double angle = 360.0 / nSteps;

double oldx = x + r, oldy = y, newx, newy;

for(double i = angle; i <= 360 + angle; i += angle){

newx = r * Math.cos(Math.toRadians(i)) + x;

newy = r * Math.sin(Math.toRadians(i)) + y;

da.line(oldx, oldy, newx, newy);

oldx = newx;

oldy = newy;

}

Small problem... but annoying!!!!!

Thanks for the help Paul. Much appreciated.....

Handing in tomorrow......

Jenski xxx

Actually, with all respect, a step backward.

Error. This draws one too many sections. And don't use doubles as indices.

Your original program was better because it used an integer index, which

meant it always stopped at the same place.

This business of using doubles as indices is a very common student error,

and it results in unexpected, subtle bugs, jusat like the one you saw when

the circle wouldn't draw correctly. But instead of thinking it through, you

just added an extra quantity onto the upper limit test:

i <= 360 + angle;

Which most of the time will draw one segment twice, but not in exactly the

same place, and over time this design choice will turn out to have been a

bad idea.

You have not defined x and y in the posted listing. Do try to incude

everything that is used in the listing.

Does this routine actually accept doubles? Did you actually compile and run

this code? This is why we like to see the use of *known* classes in posted

listings. Graphics.drawLine() requires the use of integers.

What? Now you have real problems, ones your professor will very likely

notice, as I did.

I think you are in too much of a hurry. The integer-indexed version was

better in principle.

--

Paul Lutus

http://www.yqcomputer.com/

I'd have to agree with most of Pauls comments.

Try nesting your drawing code within a for loop...

for (i=1;i<=nsteps;i++){

...

...

}

All points on a screen are in Integers (unless someone went and changed

it while I wasn't looking).

Just something that springs to mind....

Your current code would draw a diamond if you had nsteps equal to 4.

You could ensure that all shapes are drawing right side up by..

if (nsteps mod 2 =0){

angle = angle/2;

}

else if (nsteps =3){

angle = 90;

}

Note the last ife statement would adjust the angle so that the point of

an equilateral triangle is drawn at the top and not at 0 degrees.

Just a suggestion....

Try writing it in Pseudo to start off with. Cycle through your maths

algorithms and loops using values you can calculate in your head (ie

nsteps =4) and test the values.

If you'd have plugged nsteps=4 into your code it would have been very

obvious you were executing the draw function once too many times.

Cheers

Starmage

Try nesting your drawing code within a for loop...

for (i=1;i<=nsteps;i++){

...

...

}

All points on a screen are in Integers (unless someone went and changed

it while I wasn't looking).

Just something that springs to mind....

Your current code would draw a diamond if you had nsteps equal to 4.

You could ensure that all shapes are drawing right side up by..

if (nsteps mod 2 =0){

angle = angle/2;

}

else if (nsteps =3){

angle = 90;

}

Note the last ife statement would adjust the angle so that the point of

an equilateral triangle is drawn at the top and not at 0 degrees.

Just a suggestion....

Try writing it in Pseudo to start off with. Cycle through your maths

algorithms and loops using values you can calculate in your head (ie

nsteps =4) and test the values.

If you'd have plugged nsteps=4 into your code it would have been very

obvious you were executing the draw function once too many times.

Cheers

Starmage

I'm not sure of how your method da.line takes values, does it take

doubles or integers? I would have thought integers since (as far as I

recall) points on the screen are denotes as ints.

This is a pretty simple mathematical problem. As Paul points out you

are really drawing polygons. (a shape that has equal sides and angles).

I would have suggested you read the class Point for some further ideas.

But I would have done the following......

Point origin = new Point(x,y);

double angle = 360.0/nsteps;

Point points[] = new Point[nsteps];

for (i=0;i<nsteps;i++){

int translaterx = r*Math.cos(Math.toRadians(angle));

int translatery = r*Math.sin(math.toRadians(angle));

points[i] = origin.translate(translaterx,translatery);

}

points[nsteps] = points[0];

for (j=0;j<nsteps;j++){

da.line(points[j].getX(),points[j].getY(),points[j+1].getX(),points[j+1].getY());

}

Cheers

--

___________,,,_o~o_,,,___________

The Power to Imagine

XXXX@XXXXX.COM

___________,,,_____,,,___________

'

doubles or integers? I would have thought integers since (as far as I

recall) points on the screen are denotes as ints.

This is a pretty simple mathematical problem. As Paul points out you

are really drawing polygons. (a shape that has equal sides and angles).

I would have suggested you read the class Point for some further ideas.

But I would have done the following......

Point origin = new Point(x,y);

double angle = 360.0/nsteps;

Point points[] = new Point[nsteps];

for (i=0;i<nsteps;i++){

int translaterx = r*Math.cos(Math.toRadians(angle));

int translatery = r*Math.sin(math.toRadians(angle));

points[i] = origin.translate(translaterx,translatery);

}

points[nsteps] = points[0];

for (j=0;j<nsteps;j++){

da.line(points[j].getX(),points[j].getY(),points[j+1].getX(),points[j+1].getY());

}

Cheers

--

___________,,,_o~o_,,,___________

The Power to Imagine

XXXX@XXXXX.COM

___________,,,_____,,,___________

'

Sorry... missed one line in my code....

angle+=angle;

--

___________,,,_o~o_,,,___________

The Power to Imagine

XXXX@XXXXX.COM

___________,,,_____,,,___________

'

angle+=angle;

--

___________,,,_o~o_,,,___________

The Power to Imagine

XXXX@XXXXX.COM

___________,,,_____,,,___________

'

Please! People, if you are going to post code. PLEASE TEST IT FIRST. The

above "fix" is totally broken, the original code was broken, and you are

trying to tutor a beginner, who can't figure this out for himself.

STOP POSTING BROKEN CODE.

THINK! What does this --

angle+=angle;

-- do? Answer: not what you seem to think.

Starmage, you arready have a reputation for typing code into your newsreader

without any reality check with a compiler. Please break this habit today.

--

Paul Lutus

http://www.yqcomputer.com/

Oh well

That shoulda been

agent+=360.0/nsteps;

My mistake.

In any case the code still needs adjusting to make the translaters

Integers and not doubles.

Paul Lutus wrote:

--

___________,,,_o~o_,,,___________

The Power to Imagine

XXXX@XXXXX.COM

___________,,,_____,,,___________

'

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">

<title></title>

</head>

<body>

Oh well<br>

That shoulda been<br>

agent+=360.0/nsteps;<br>

My mistake.<br>

In any case the code still needs adjusting to make the translaters Integers

and not doubles.<br>

<br>

Paul Lutus wrote:<br>

<blockquote type="cite" cite=" XXXX@XXXXX.COM ">

<pre wrap="">Starmage wrote:

</pre>

<blockquote type="cite">

<pre wrap="">Sorry... missed one line in my code....

Starmage wrote:

</pre>

<blockquote type="cite">

<pre wrap="">I'm not sure of how your method da.line takes values, does it take

doubles or integers? I would have thought integers since (as far as I

recall) points on the screen are denotes as ints.

This is a pretty simple mathematical problem. As Paul points out you

are really drawing polygons. (a shape that has equal sides and angles).

I would have suggested you read the class Point for some further

ideas. But I would have done the following......

Point origin = new Point(x,y);

double angle = 360.0/nsteps;

Point points[] = new Point[nsteps];

for (i=0;i<nsteps;i++){

int translaterx = r*Math.cos(Math.toRadians(angle));

int translatery = r*Math.sin(math.toRadians(angle));

points[i] = origin.translate(translaterx,translatery);

</pre>

</blockquote>

<pre wrap=""> angle+=angle;

</pre>

</blockquote>

<pre wrap=""><!---->

Please! People, if you are going to post code. PLEASE TEST IT FIRST. The

above "fix" is totally broken, the original code was broken, and you are

trying to tutor a beginner, who can't figure this out for himself.

STOP POSTING BROKEN CODE.

THINK! What does this --

angle+=angle;

-- do? Answer: not what you seem to think.

Starmage, you arready have a reputation for typing code into your newsreader

without any reality check with a compiler. Please break this habit today.

</pre>

</blockquote>

<br>

<pre class="moz-signature" cols="$mailwrapcol">--

___________,,,_o~o_,,,___________

The Power to Imagine

<a class="moz-txt-link-abbreviated" href="mailto: XXXX@XXXXX.COM "> XXXX@XXXXX.COM </a>

___________,,,_____,,,___________

'

</pre>

<br>

</body>

</html>

1. Event ID: 2012 / 2013 SMTPSVC [ANNOYING ANNOYING ANNOYING]

3. Migrating desktop apps to Java ME's CDC

4. ME's startup doesn't go further than the green screen-sys reg

5. ME's startup doesn't go further than the green screen

6. Alert me's

7. why am I getting this annoying message each time?

8. Am I the only one annoyed by ORA- error message sites?

11. I am annoyed by IE underlinings

14. Help I am going crazy I am trying to merge a label list excel

9 post • Page:**1** of **1**