Shadowing Posted February 14, 2016 Share Posted February 14, 2016 Every year I run into some math that is over my head lol. Say I have a circle with a radius of 600 and I want to place 20 objects around the circle perfectly spaced. I need to figure out what the x and y would be for each object. Quote Link to comment https://forums.phpfreaks.com/topic/300807-math-god-needed/ Share on other sites More sharing options...
requinix Posted February 14, 2016 Share Posted February 14, 2016 "Perfectly" spaced how? 20 isn't a nice number like 19 (hexagonal) or 25 (square). Quote Link to comment https://forums.phpfreaks.com/topic/300807-math-god-needed/#findComment-1531092 Share on other sites More sharing options...
Solution Barand Posted February 14, 2016 Solution Share Posted February 14, 2016 If you want them spaced around the circumference then the attached diagram will tell you what you need to know Quote Link to comment https://forums.phpfreaks.com/topic/300807-math-god-needed/#findComment-1531099 Share on other sites More sharing options...
Shadowing Posted February 14, 2016 Author Share Posted February 14, 2016 (edited) Thanks for thee responses guys. Ya I meant spaced around its circumference. So together all 20 objects forms a circle. I think this is the formula I saw when I was trying to google it Barand. I'm confused about the theta part Do I use pie for that? Also not sure how this would give me 20 spaced out. But I guess the theta would determine that. so really I need 20 slices of pie and a object in the middle of each slice on the circumference. Maybe I need to find the circumference first then divide it out by 20. Then find what each one would be spaced out on the circumference. Then some how use that number with a formula to find my x and y? Edited February 14, 2016 by Shadowing Quote Link to comment https://forums.phpfreaks.com/topic/300807-math-god-needed/#findComment-1531109 Share on other sites More sharing options...
Barand Posted February 14, 2016 Share Posted February 14, 2016 All you need is theta. You have 20 objects so theta will start at zero and increase by 2*PI/20 for each one. Then, as in the diagram, if the circle has radius R and its centre is at cx,cy the x,y coordinates for each object are x = cx + R * cos(theta) y = cy - R * sin(theta) Quote Link to comment https://forums.phpfreaks.com/topic/300807-math-god-needed/#findComment-1531110 Share on other sites More sharing options...
Shadowing Posted February 14, 2016 Author Share Posted February 14, 2016 Ahh OK. Thanks now I know how to find theta. I can just ignore cy and CX right since that's always going to be 0,0? Quote Link to comment https://forums.phpfreaks.com/topic/300807-math-god-needed/#findComment-1531111 Share on other sites More sharing options...
Barand Posted February 14, 2016 Share Posted February 14, 2016 0,0 is usually at the top left corner of the image. Quote Link to comment https://forums.phpfreaks.com/topic/300807-math-god-needed/#findComment-1531112 Share on other sites More sharing options...
Shadowing Posted February 14, 2016 Author Share Posted February 14, 2016 Actually this is for unity game engine. Atm center is 0,0 So I'm dealing with negative numbers Quote Link to comment https://forums.phpfreaks.com/topic/300807-math-god-needed/#findComment-1531113 Share on other sites More sharing options...
Shadowing Posted February 14, 2016 Author Share Posted February 14, 2016 (edited) Actually the zero probably affects if the vakue is negative or not Edited February 14, 2016 by Shadowing Quote Link to comment https://forums.phpfreaks.com/topic/300807-math-god-needed/#findComment-1531114 Share on other sites More sharing options...
Barand Posted February 14, 2016 Share Posted February 14, 2016 Here's an example <?php $width = 140; $height = 140; $rad = 60; $dtheta = M_PI/10; $im = "<svg width=\"$width\" height=\"$height\" viewBox=\"0 0 $width $height\" >\n <rect x='1' y='1' width='$width' height='$height' fill='black' />\n <g transform='translate(70,70)'>\n <circle cx='0' cy='0' r='$rad' stroke='white' fill='none' />\n"; for ($theta=0; $theta<2*M_PI; $theta+=$dtheta) { $x = $rad*cos($theta); $y = $rad*sin($theta); $im .= "<circle cx='$x' cy='$y' r='5' fill='cyan' />\n"; } $im .= "</g></svg>\n"; echo $im; ?> 2 Quote Link to comment https://forums.phpfreaks.com/topic/300807-math-god-needed/#findComment-1531115 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.