# Thread: Finding a point of a triangle from two known points, one angle and two lengths

1. ## Finding a point of a triangle from two known points, one angle and two lengths

Hi,

I'm a programmer and was just playing about with some AI for a game.

There is a moving object which has a target point it is travelling to. It will travel to this point directly except it may need to evade a circular area. I'm trying to find the point to use as an intermediary target to evade the circle.

Attached is an image which shows the situation.

On that image:

• Point a is the target of the object
• Point b is the object itself
• Point c is the center point of the circle to avoid
• Point d is the point we're trying to find
• Points a, c and d are known
• The length of the dotted line dc is known

The circle is probably not necessary.

In my head ab and cd are perpendicular (??).

The angle inside point c (ie the angle opposite ab within the triangle abc) is known. I'll call this theta just for a moment.

In the triangle bcd the angle inside c (ie the angle opposite db) is half theta.

I keep drawing lots of pretty pictures but haven't actually got anywhere with the problem! I could probably work it out if ab was parallel to the y axis (2d space) but I cannot guarantee that it will be so there's my problem!

Any thoughts on the above?

Thanks in advance,
Kazatan

2. ## Re: Finding a point of a triangle from two known points, one angle and two lengths

Originally Posted by Kazatan
Hi,

I'm a programmer and was just playing about with some AI for a game.

There is a moving object which has a target point it is travelling to. It will travel to this point directly except it may need to evade a circular area. I'm trying to find the point to use as an intermediary target to evade the circle.

Attached is an image which shows the situation.

On that image:

• Point a is the target of the object
• Point b is the object itself
• Point c is the center point of the circle to avoid
• Point d is the point we're trying to find
• Points a, c and d are known

The two points immediately preceding this sentence are contradictory. Did you mean a, b, and c are known?

• The length of the dotted line dc is known

The circle is probably not necessary.

In my head ab and cd are perpendicular (??).

The angle inside point c (ie the angle opposite ab within the triangle abc) is known. I'll call this theta just for a moment.

In the triangle bcd the angle inside c (ie the angle opposite db) is half theta.

I keep drawing lots of pretty pictures but haven't actually got anywhere with the problem! I could probably work it out if ab was parallel to the y axis (2d space) but I cannot guarantee that it will be so there's my problem!

Any thoughts on the above?

Thanks in advance,
Kazatan

3. ## Re: Finding a point of a triangle from two known points, one angle and two lengths

Ah yes. My proof reading skills need as much work as my maths skills!

I know points a, b and c and i'm trying to find point d.

Sorry for the confusion! Is there any way I can edit my original post?

4. ## Re: Finding a point of a triangle from two known points, one angle and two lengths

No need to edit the OP.

So now I have a few more questions:

1. What is the "general criteria" that says how far out d has to be? Does it just need to be on the circumference of the circle? Or do you need clearance for a physical object with a certain size?

2. Do you know the radius of the circle?

3. It looks as though point b is inside the circle, the way you've drawn it. If that's the destination, then there's no way you can avoid the circle if the destination is inside the circle! There's probably some fancy topological argument why you can't avoid the circle in such a case, but I view it as not needing proof.

5. ## Re: Finding a point of a triangle from two known points, one angle and two lengths

Ok so to answer each question:

1. It will be the radius of the circle plus the radius of the moving object but as far as the calculation is concerned it can be a known value.

2. I do know the radius of the circle. The circle is a danger zone perceived by the moving object and the radius depends on some attributes of that object. Again - for the calculation this can be a known value.

3. The AI routine takes place after the movement routine so the AI will only trigger "I'm in a danger zone!" when it is in the danger zone. So I purposely drew the point inside the circle. The AIs response to being in the danger zone is to move out of the danger zone whilst making best progress towards its target.

I hope they shed some more light on the problem. Thanks for the interest so far

6. ## Re: Finding a point of a triangle from two known points, one angle and two lengths

So, let me see if I can restate the problem. Object b is trying to get to point a: that's its final destination. On the way, it might find itself in a circular danger zone, centered at point c, and of a known radius. Your answer to my third question above indicates that the object b, while completely unable to detect danger zones in advance, is quite capable of mapping out all the information relating to a danger zone if it finds itself inside one. Correct?

So now my question becomes this: given the situation you've drawn in the OP, does the object b want to move straight from its starting point ("at b") to point d? And is the goal to completely avoid the danger zone after reaching point d? Because if the distance from c to d is equal to the danger zone radius plus the object radius, then in moving from d to a, the object will get back into the danger zone a little bit. The reason for that, is that in order for object b to avoid the danger zone, you really have to allow enough room for object b at the point of closest approach on the path from d to a. Let p be object b's position on the line da. Then the point of closest approach to c occurs when pa is orthogonal to pc. That point will not be d. Do you follow? So, what you really need is the following: let q be the point on line da that is closest to c. That is, qa is perpendicular to qc. Then qc is equal to the object radius plus the danger zone radius. That would get you out of the danger zone, and not back into it. Alternatively, if da is already perpendicular to dc, then q = d, and I'd say your scheme would work.

7. ## Re: Finding a point of a triangle from two known points, one angle and two lengths

I kind of follow what you are saying, but maybe some crucial information about the game mechanics is missing.

Object b has some user defined points it is attempting to get to. Point a is an example of one of these; there may be more points afterwards.

Object b chooses the first point in the list and attempts to move there. The motion is controlled by a movement system I have created. It required a point (a point being an x and y coordinate pair) as a target. The motion engine uses acceleration, speed, angle plus some other information (maximums, deceleration based on changes in angle etc.)

During objects b's motion it can also show some AI behaviours, one of which is to attempt to avoid obstacles such as object c. Object b has some stats - such as perception - which will determine how close object b is to object c before it starts to evade it. This is the danger zone (circle).

As the motion engine is based on a target point (x, y pair) I require an intermediary point to travel to for the engine to work. My brain told me that a point which was one end of the line dc which was orthogonal to the line ab and the length of the line dc was danger-zone-radius plus object-b-radius would satisfy this in the most optimal manner. This may not be true but it was the thought I went with. My issue being I couldn't think of a way to work out the location of this point.

Whilst writing this message and with the weekend break I may well have figured out how to achieve this. The quotes in your signatures may well be totally relevant to this thread!
My thoughts are based on this assumption: If I create a right angled triangle with the line ab as the hypotenuse then it is similar to a right angled triangle with cd as a hypotenuse when ab is orthogonal to cd.

PS: I'm not 100% on the true maths meaning of orthogonal but in my text above it means that were to two lines to intersect then the angle between them would be 90 degrees!

8. ## Re: Finding a point of a triangle from two known points, one angle and two lengths

Can you pick point d? That is, do you have control over where d is? I would draw up a sketch of the situation, but my computer drawing skills are not the best.