kubapl 127 Report post Posted February 18, 2011 I am trying to arrange bricks in a circular manner. I pretty much am taking the width of the brick image and dividing that by the hypo which is the radius of the circle and inverse cosining it. This give me the angle step that I need to use to figure out the x and y positions of the brick. I find that I still have some over lap in 1 spot. Heres a screenshot: [attachment=1447:overlap.png] I set the bricks alpha so you can better see the over lap Heres the code that I do the calculations: [code] private void DrawCircle( int radius ) { float x = 0.0f; float y = 0.0f; double angle = 0.0f; double angleStepSize = Math.Acos( (double)( texBrick.Width ) / (double)radius ) * ( Math.PI / 180 ); while( angle < 2 * Math.PI ) { x = ( float ) ( radius * Math.Cos( angle ) ); y = ( float ) ( radius * Math.Sin( angle ) ); spriteBatch.Draw( texBrick, new Vector2( x + graphics.GraphicsDevice.Viewport.Width / 2, y + graphics.GraphicsDevice.Viewport.Height / 2 ), new Rectangle( 0, 0, texBrick.Width, texBrick.Height ), new Color( 0.1f, 0.1f, 0.1f, 0.1f ), ( float ) ( (float)angle + 90.0f * ( Math.PI / 180.0f ) ), new Vector2( texBrick.Width * 0.5f, texBrick.Height * 0.5f ), 1.0f, SpriteEffects.None, 1.0f ); angle += angleStepSize * ( 3 * Math.PI ); } } [/code] The final line I do angle += angleStepSize * (3 * Math.PI ) I'm not sure why I added the 3 * Math.PI ... in my mind the angleStepSize should be enough. 0 Share this post Link to post Share on other sites
digitaldisciple 102 Report post Posted February 18, 2011 In order for the bricks to be divided evenly, it must be true that (2 * pi) % angleStepSize = 0. In other words, you must be able to divide 2 * pi by angleStepSize without any remainder. I believe that's what's going on with the outer circle...using the brick width in your equation will not guarantee that this condition is satisfied. Instead of using the brick width in your calculation of angleStepSize, you'll need to make sure you're using a value that divides 360 degrees without a remainder. So maybe you'll want to compute the smallest value > brickWidth + some gap size that divides evenly into 360. Something like that. 0 Share this post Link to post Share on other sites
EricTheRed 146 Report post Posted February 18, 2011 [quote name='DigitalDisciple' timestamp='1298048608' post='4775960'] In order for the bricks to be divided evenly, it must be true that (2 * pi) % angleStepSize = 0. In other words, you must be able to divide 2 * pi by angleStepSize without any remainder. I believe that's what's going on with the outer circle...using the brick width in your equation will not guarantee that this condition is satisfied. I'm not sure what the best solution is at the moment, but there's the problem. [/quote] If you do this, re-assign angleStepSize to 2 * PI / floor(2 * PI / angleStepSize). Essential you are finding the most bricks you can fit (an integer) given their size, then dividing the arc evenly among them. 0 Share this post Link to post Share on other sites
kubapl 127 Report post Posted February 18, 2011 [quote name='EricTheRed' timestamp='1298049316' post='4775965'] [quote name='DigitalDisciple' timestamp='1298048608' post='4775960'] In order for the bricks to be divided evenly, it must be true that (2 * pi) % angleStepSize = 0. In other words, you must be able to divide 2 * pi by angleStepSize without any remainder. I believe that's what's going on with the outer circle...using the brick width in your equation will not guarantee that this condition is satisfied. I'm not sure what the best solution is at the moment, but there's the problem. [/quote] If you do this, re-assign angleStepSize to 2 * PI / floor(2 * PI / angleStepSize). Essential you are finding the most bricks you can fit (an integer) given their size, then dividing the arc evenly among them. [/quote] So I've tinkered with the numbers and did angle += ( 2 * Math.PI / Math.Floor( 2 * Math.PI / angleStepSize ) ); as you suggested but it appears as I lost all the width plus the distance in between the blocks by making this change If you look at the bottom left of the screen thats how big the block is its Width : 18 x Height 9 [attachment=1449:overlap.png] 0 Share this post Link to post Share on other sites
EricTheRed 146 Report post Posted February 18, 2011 It shouldn't be +=. just equal. Also, in your original code, why do you divide by Math.PI by 180? All of the trigonometric functions are in radians, are they not? You seem to be mixing radians and degrees though out your code. I have a feeling your angleStepSize is much to small to begin with. 0 Share this post Link to post Share on other sites
kubapl 127 Report post Posted February 18, 2011 [quote name='EricTheRed' timestamp='1298054259' post='4776014'] It shouldn't be +=. just equal. Also, in your original code, why do you divide by Math.PI by 180? All of the trigonometric functions are in radians, are they not? You seem to be mixing radians and degrees though out your code. I have a feeling your angleStepSize is much to small to begin with. [/quote] I was under the impression that they were degrees. If I just initialize the angleStepSize to this double angleStepSize = Math.Acos( ( double ) ( texBrick.Width ) / ( double ) radius ); my number is 1.4580576603128359. Also if I just make the angle equal to the step size like this angle = 2 * Math.PI / Math.Floor( 2 * Math.PI / angleStepSize ); the app just hangs and then crashes with an error saying "An unhandled exeption of type "System.OutOfMemoryException" occurred in mscorlib.dll" 0 Share this post Link to post Share on other sites
EricTheRed 146 Report post Posted February 18, 2011 The angleStepSize should be the 2 * PI / number of bricks. The number of bricks you can fit around the outside is floor(2 * PI * radius / (brick size + gap)). Try redoing your code, it doesn't seem to make much sense right now. 0 Share this post Link to post Share on other sites