Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

**SmellyMan****Member**- Registered: 2011-03-06
- Posts: 63

Hi!

I stumbled upon a problem that I was not able to solve at school with help of my teachers.

Info:

There are 2 circles. Each has its own radius and speed.

Circle 1 is going from point A to point B. Circle 2 from C to D.

They travel in 2D space in any direction and can have the same start, end or both.

All of the above data is known.

Question:

When will center of circle 2 be inside circle 1 and when it will go out of circle 1, if it will even be inside?

How long is it inside? ( exitTime - entryTime)

Programming language that I'll be using for a solution doesn't really matter ( C++ most likely, but C# is considered as another option).

Simulation is not an option.

I hope I made myself clear enough.

Regards!

If I misused any name in English I apologize and please correct me.

*Last edited by SmellyMan (2013-02-22 04:28:56)*

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 92,942

Hi;

What are the speeds of the circles? What are the sizes of the circles? How big is the space they are moving in? What law governs their motion? There are many more questions.

**In mathematics, you don't understand things. You just get used to them.**

**I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.**

Offline

**SmellyMan****Member**- Registered: 2011-03-06
- Posts: 63

I need just basic equation how to calculate this.

You can take sample data any you like ( or I can make some up, I don't have any with known solution).

Their motion is linear (I hope used a correct phrase).

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 92,942

Hi;

There is a method to find whether two circles overlap.

**In mathematics, you don't understand things. You just get used to them.**

**I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.**

Offline

**SmellyMan****Member**- Registered: 2011-03-06
- Posts: 63

bobbym wrote:

Hi;

There is a method to find whether two circles overlap.

This is a friend of him speaking and I'll try make it as clear as possible.

Imagine you have two tanks that have different ranges of fire (we're trying to make a game ). These tanks will move in a linear path, the path can be just about anything you imagine. The radius of the circle can also be "random". These paths can intersect, go parellel or move away from each other. As pointed, the range and the size of the circle is also almost any various number.

Let's take an example:

The tanks intersect at a 45 degree angle towards each other in a 2d plane of a limited size (this size limit can be made up if you so desire).

Tank A:

Moves at 20 m/s.

Has a range of 50m.

Moves for 100m.

Tank B:

Moves at 50 m/s.

Has a range of 30m.

Moves for 200m.

Also, as you can imagine, they have a starting point and an ending point, so it's not always necessary they start in the corner of the plane. They can be at any given point in this limited area.

Now, we have to know for how long the tank A will be shooting at tank B and the other way around. Keep in mind that there can be as many units on the field, but we're using two as an example. What we basically want to know, how to calculate when and for how long the tank will shoot other units.

Hopefully I've made it clear, thank you for taking your time!

EDIT: So if you imagine, the center point of the tank A has to be in the radius of tank B in order for it to start shooting. And the center point of tank B has to be in the radius of A to do the same.

*Last edited by SmellyMan (2013-02-22 05:00:54)*

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 92,942

The positions of the tanks are known so they do not need to be calculated. What you require is when the circle overlap contains the center point of the other circle.

*Last edited by bobbym (2013-02-22 05:06:15)*

**In mathematics, you don't understand things. You just get used to them.**

**I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.**

Offline

**SmellyMan****Member**- Registered: 2011-03-06
- Posts: 63

bobbym wrote:

The positions of the tanks are known so they do not need to be calculated. What you require is when the circle overlap contains trhe center point of the other circle.

Yes, exactly!

Thank you for responding.

*Last edited by SmellyMan (2013-02-22 05:06:31)*

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 92,942

Hi;

I will work on it and see what I can get.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**SmellyMan****Member**- Registered: 2011-03-06
- Posts: 63

bobbym wrote:

Hi;

I will work on it and see what I can get.

Thank you very much, I feel kind of bad for abusing your time, but it is very much appreciated. Don't feel rushed in any way.

Thank you again.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 92,942

Do you have the equations of the circles that represent where the tank can fire or do you need it?

If you have these equations the problem is trivially solved, if you do not I will show you how to get them. After that you can program it very easily in C++.

*Last edited by bobbym (2013-02-22 05:46:18)*

**In mathematics, you don't understand things. You just get used to them.**

Offline

**SmellyMan****Member**- Registered: 2011-03-06
- Posts: 63

bobbym wrote:

Do you have the equations of the circles that represent where the tank can fire or do you need it?

If you have these equations the problem is trivially solved, if you do not I will show you how to get them. After that you can program it very easily in C++.

No, I do not have any equations of the circles, it is one of our bigger problems in the process.

Best regards.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 92,942

You have the positions of the tanks in (x,y) coordinates, which you will call the centers of the circles? You have the firing radius?

**In mathematics, you don't understand things. You just get used to them.**

Offline

**SmellyMan****Member**- Registered: 2011-03-06
- Posts: 63

bobbym wrote:

You have the positions of the tanks in (x,y) coordinates, which you will call the centers of the circles? You have the firing radius?

Yes, that is right. I also have the firing radius.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 92,942

The equation that gives you the circle which represents where a tank can fire is

( x0 , y0 ) is the ordered pair which is the tank position and r is the firing radius.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**SmellyMan****Member**- Registered: 2011-03-06
- Posts: 63

bobbym wrote:

The equation that gives you the circle which represents where a tank can fire is

( x0 , y0 ) is the ordered pair which is the tank position and r is the firing radius.

If the x0 and y0 is the current position of the tank in a 2d plane, we basically substract the full length of the axis to get a pythagoras theorem?

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 92,942

Hi;

It is not necessary to figure anything now. I just want you to understand visually in a cartesian geometry sort of way.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**SmellyMan****Member**- Registered: 2011-03-06
- Posts: 63

bobbym wrote:

Hi;

It is not necessary to figure anything now. I just want you to understand visually in a cartesian geometry sort of way.

Yes I've drawn it myself and I've come to understand it, it's not all that complicated. I appreciate the picture!

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 92,942

The position of the other tank, the victim, is within range of the first tank when its center is on the circle or inside it.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**SmellyMan****Member**- Registered: 2011-03-06
- Posts: 63

bobbym wrote:

The position of the other tank, the victim, is within range of the first tank when its center is on the circle or inside it.

Yes, that is also correct.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 92,942

Okay, hold on while I try to get the answer.

Take the xy coordinates of the second tank's position and plug them into the first tanks equation for the circle. That will give you the answer you want.

*Last edited by bobbym (2013-02-22 06:42:40)*

**In mathematics, you don't understand things. You just get used to them.**

Offline

**SmellyMan****Member**- Registered: 2011-03-06
- Posts: 63

bobbym wrote:

Okay, hold on while I try to get the answer.

Take the xy coordinates of the second tank's position and plug them into the first tanks equation for the circle. That will give you the answer you want.

This means the formula would look like this:

P1 (x,y) - First tank center

P2 (q,w) - Second tank center

*Last edited by SmellyMan (2013-02-22 06:54:44)*

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 92,942

Hi;

Not exactly, I will provide an example that will make all of this clear. Please hold while I draw it up.

**In mathematics, you don't understand things. You just get used to them.**

Offline

**SmellyMan****Member**- Registered: 2011-03-06
- Posts: 63

bobbym wrote:

Hi;

Not exactly, I will provide an example that will make all of this clear. Please hold while I draw it up.

I'm sorry for any grief I may have caused. I have one more question, but perhaps it'll be resolved when you draw it, so it'll be more clear to me.

Thank you for your time!

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 92,942

In the drawing below you are the red tank. You are located at (6,1). You have a firing radius of 5. The equation of the circle for your tank is:

There are three enemy tanks they are in blue.

Tank1 is at (10,5) to find out if he is in range you just plug into this inequality,

4^2 + 4^2 is not ≤ to 25 so that tank is out of range as the drawing shows.

Tank2 is at (6,6), plugging in,

0^2 + 5^2 is ≤ to 25 so that tank is in range.

Tank3 is at (9,0), plugging in,

3^3 +(-1)^2 is is ≤ 25 so that tank is in range too as the drawing shows.

*Last edited by bobbym (2013-02-22 07:27:45)*

**In mathematics, you don't understand things. You just get used to them.**

Offline

**SmellyMan****Member**- Registered: 2011-03-06
- Posts: 63

Yes, thank you, I figured it'd work like this. Basically you're just comparing the distance between the tanks, and if it's equal or less than the radius, it means that the tank 1 will attack the others.

There is however a different problem we're facing now, we've tackled the problem of figuring if they're inside the zone or not, the problem is because the tanks are moving. They're not stationary as portrayed.

As said, they're moving from point A to point B in a 2d limited plane. Both of them have a certain speed and the problem is that we'd like to figure out for how long would the tanks be in the shooting range of each other.

Figuring out if they're parallel, crossing and the angle of crossing isn't a problem. What we're basically looking for, when will the shooting start and for how long will the tank 1 shoot tank 2. Again, they're moving at different speeds and they have different paths with different lengths.

Offline