Jump to content

coordinates of polygon


srinivas6203

Recommended Posts

This gives a regular hexagon.

 

$rad is the radius

 

Set $step to 360 / (number of sides) for others

 

<?php
header("Content-type: image/png");
$im = imagecreate(200, 200);
$green = imagecolorallocate($im, 0, 255, 0);
$red = imagecolorallocate($im, 255, 0, 0);

$step = 60;
$rad = 80;
$centrex = imagesx($im)/2;
$centrey = imagesy($im)/2;

for ($i=0; $i<360; $i+=$step)
{
    $points[] = $centrex + $rad*cos(deg2rad($i));
    $points[] = $centrey + $rad*sin(deg2rad($i));
}

$vertices = count($points) / 2;
imagepolygon($im, $points, $vertices, $red);
imagepng($im);
imagedestroy($im);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.