Jump to content
  • Advertisement
Sign in to follow this  
Icebone1000

How many circles of radius r1 at the border of a cyrcle with radius r2?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Or a better question would be, how do I distribute circles around another cyrcle?

I have top view towers of varying size, and a smoke animation fx of fixed syze, when the towers are destroyed I want to spawn the smoke animations in a way that covers all the tower border.

 

I dont know how much I have to rotate the next smoke fx so that its justing touching the previous..whats the relation between radius, angle and distance from the rotation pivot?

Edited by Icebone1000

Share this post


Link to post
Share on other sites
Advertisement
If "approximate" is good enough, which is likely the case with a smoke sprite (as it's fluffy with unsharp borders), just divide the circumference (2*pi*r2) by the smaller circle's diameter (2*r1). This is not terribly "correct" if the radii are quite similar, but if r2 >> r1, nobody will notice. Besides, you can't add half a sprite anyway...

If you want it precise, you must use the chord length instead, which is much more complicated to calculate, involving inverse trig functions. The half cord length divided by the radius is the sine, so there you can get the (half) angle via arcsin, and divide 2pi by that. But... to what avail, you can still only have a discrete number.

Be sure you really need a precise solution first.

Share this post


Link to post
Share on other sites

Im dividing by the smoke radius instead of diameter, using diameter it leaves a gap.

 

To compute the pos between each smoke I made a proportion with the radius of the tower and 180 degrees, not sure if this is entirely correct, but it works.

The logic is, if in 180 degrees the "distance" displaced is 2*r, then how many angle rot is for the smoke radius:

float angleStep = (180.0f * fxRadius) / (coll.radius * 2.0f);

void SpawnTowerDestructionFx(CircleCollider2D coll)
	{
		float circunf = Mathf.PI * coll.radius * 2.0f;

		float fxRadius = 0.8f;// not really at the border, smokes overlap
		//float fxDiameter = fxRadius * 2.0f;

		int nFxs = (int)(circunf / fxRadius); // this is not precise computation either

		Vector2 towerPos = transform.position;

		float angleStep = (180.0f * fxRadius) / (coll.radius * 2.0f);

		for (int it = 0; it < nFxs; ++it)
		{
			float angle = it * angleStep;

			Quaternion rot = Quaternion.Euler(0.0f, 0.0f, angle);
			Vector2 dir = rot * Vector2.right;
			Vector2 pos = towerPos + dir * coll.radius;

		    spriteFxPooling.PoolObject().GetComponent<SpriteFX>().
		    Launch(pos, rot, SpriteFX.AnimHashes.SMOKE);
		}
	}
Edited by Icebone1000

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!