Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^3: Creating a circle in a data structure

by Crackers2 (Parson)
on May 29, 2007 at 03:08 UTC ( #617910=note: print w/replies, xml ) Need Help??

in reply to Re^2: Creating a circle in a data structure
in thread Creating a circle in a data structure

Yes you're right. To complete the outline you have to connect each point to the previous point. Something like this:

$prevdist = 0; foreach $ydist ( 0..$radius ) { # using the formula: # xdist*xdist + ydist*ydist = radius*radius $newxdist = int(sqrt( $radius*$radius - $ydist*$ydist)); # Take advantage of symmetry to plot 4 lines at once # (for circle outline, draw a line from the previous # point to the new one) foreach $xdist ($prevdist..$newxdist) { $circle{$x_center-$xdist}{$y_center-$ydist}++; $circle{$x_center+$xdist}{$y_center-$ydist}++; $circle{$x_center-$xdist}{$y_center+$ydist}++; $circle{$x_center+$xdist}{$y_center+$ydist}++; } $prevdist = $newxdist; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://617910]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2018-10-23 08:02 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (125 votes). Check out past polls.