Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Creating a circle in a data structure

by AK108 (Friar)
on May 28, 2007 at 20:17 UTC ( [id://617878]=note: print w/replies, xml ) Need Help??


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

When using the whole disc, it works nicely. The individual points do not work, unfortunately.

I can use the whole disc method, but I need to be able to calculate the distance from the center of the circle. I've tried many formulas, and some look close (working for x values or y values), but nothing actually works.

  • Comment on Re^2: Creating a circle in a data structure

Replies are listed 'Best First'.
Re^3: Creating a circle in a data structure
by Crackers2 (Parson) on May 29, 2007 at 03:08 UTC

    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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-05-25 07:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found