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

Started by
0 comments, last by Icebone1000 7 years, 5 months ago

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?

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.

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

This topic is closed to new replies.

Advertisement