Public Group

# Math Circle Help

This topic is 2772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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:
 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 ); } } 

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.

##### Share on other sites
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.

##### Share on other sites

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.

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.

##### Share on other sites

[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.

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]

##### Share on other sites
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.

##### Share on other sites

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.

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"

##### Share on other sites
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.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5
frob
13

• 9
• 15
• 10
• 9
• 17
• ### Forum Statistics

• Total Topics
632602
• Total Posts
3007363

×