php - Aligning rectangles around the inside of a circle and rotate -


i have program generates image.

it places x images around circle x circumference.

see below output of current implementation. current implementation example

i need of rectangles inside of circle , evenly placed.

note on image above, current implementation, of rectangles on inside , on outside.

i'm unsure wrong calculation, please see below code placing rectangles.

 /**  * draw points around circle  * @param  $count  * @param  $circumference  */ public function drawwheel($count, $circumference) {     /**      * starting angle      */     $angle = 0;      /**      * starting step between rectangles      */     $step = (2 * pi()) / $count;      /**      * center x of canvas      */     $startx = ($this->canvas['width'] / 2);      /**      * center y of canvas      */     $starty = ($this->canvas['height'] / 2);       ($i = 0; $i < $count; $i++) {         /**          * width of rectangle          */         $width = 85;          /**          * height of rectangle          */         $height = 41;          /**          * rectangle x position          */         $x = ($startx + ($circumference / 2) * cos($angle)) - $width / 2;          /**          * rectangle y position          */         $y = ($starty + ($circumference / 2) * sin($angle)) - $height / 2;          /**          * degrees rotate rectangle around circle          */         $rotateangle = atan2((($startx - ($width / 2)) - $x), (($starty - ($height)) - $y)) * 180 / pi();          /**          * rectangle image          */         $watermark = image::make(base_path('test.png'));          $watermark->opacity(75);         $watermark->resize($width, $height);         $watermark->rotate($rotateangle);          $this->image->insert($watermark, 'top-left', ceil($x), ceil($y));          /**          * increment angle          */         $angle += $step;     } } 

the part of function makes calculations below.

$x = ($startx + ($circumference / 2) * cos($angle)) - $width / 2;  $y = ($starty + ($circumference / 2) * sin($angle)) - $height / 2;  $rotateangle = atan2((($startx - ($width / 2)) - $x), (($starty - ($height)) - $y)) * 180 / pi(); 

the rotation point center of rectangle.

image rotated using: http://php.net/manual/en/function.imagerotate.php

circle drawn using: http://php.net/manual/en/function.imagefilledarc.php

these lines suspicious:

$x = ($startx + ($circumference / 2) * cos($angle)) - $width / 2; $y = ($starty + ($circumference / 2) * sin($angle)) - $height / 2; 

to place rectangle center inside circle @ inner radius, have use this:

$x = ($startx + (($circumference - $height) / 2) * cos($angle)); $y = ($starty + (($circumference - $height) / 2) * sin($angle)); 

and rotation angle simply

$rotateangle = $angle * 180 / pi - 90; // $angle+90 depending on coordinate system 

rotated watermark has bounding rectangle dimensions

fi = rotateangle * pi / 80  new_height = $width * abs(sin(fi)) + $height * abs(cos(fi)) new_width = $width * abs(cos(fi)) + $height * abs(sin(fi)) 

correct $x , $y right output:

$x = $x - new_width/2 $y = $y - new_height/2 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -