Jump to content
zapat

Need help with trigonometry

Recommended Posts

I just don't know how to search it, so I hope some geometry genius reads this and can answer.

I have a triangle like this:http://upload.wikimedia.org/wikipedia/commons/4/49/Triangle_with_notations_2.svg

I know "c", and "beta".

I don't know "a" and "b" nor "alpha" BUT I know the ratio of a and b (eg. b = 2a).

How could I get a, or alpha?

I will need it because I want two units (starting at A and B, and whose distance, and speed I know: that will give a and b ratio, but changing) to meet.

Share this post


Link to post
Share on other sites

Umm..

{ _x doMove getMarkerPos "meetingspot"} forEach [unit1, unit2];

Why do we need to get math involved for this? :) Stratis isn't a flat plain so speed won't remain the same and traveling in laser straight lines won't happen. This just seems overly complicated for a mission to me.

Share this post


Link to post
Share on other sites

It is complicated true, still the question remains. I just like experimenting with things. Some work, some don't. If I had always stayed at placing a marker in the editor - because otherwise it is too comlicated - I would have lost interest years ago now. Anyhow, one is player, so you don't know where he is going...

Share this post


Link to post
Share on other sites

Let me try and reformulate for the sake of chalenge.

Basicaly you have a speed that can give at any point in time where a certain unit1 will be on a straight line, this will give you the range for any arbitrary t1, t2, t3, etc... you know that either unit2 (depending on its speed 2x or 1/2 of unit1) will have it's range circle in any direction intersecting that unit1 straight line - the circle either intersects twice if it has the speed (one of the intersections points can be dismissed), or it never intersects due to the angle that you do know but might be diverging enough to exclude any solution.

But if it is a player anyway, at best you can make ai point towards a leading position based on current player veolicity and direction, they will eventually meet.

EDIT:

Edited by gammadust

Share this post


Link to post
Share on other sites

gammadust: for the sake of challenge only, what else! :) Thanks for your thoughts. I am not sure I can follow them throughout...

Let's give some reality to my problem.

Let's say a player drives a boat to a point, in a straight line, possibly with an unchanging speed.

I want another boat(AI) to cross it's path. In what angle should he start?

When they meet, they travelled for the same time, so the m/s from their speed will be simplified to m only: that's why I think it is a simple trigonometry question.

I only know their speed, but don't know where they will meet, so I only have a ratio of the sides of the triangle.

I was thinking on what you wrote in the last line, but I will need the angles, because if player is going in the direction of the player, (eg. 20 degrees) or 90 degrees the time factor will be different, thus different distances I need to "shoot" before the player.

Naturally this all will be recalculated like every 5 secs, so if player changes path, AI can change its as well.

Share this post


Link to post
Share on other sites

Well it can be simplified to a trigonometric question if the triangle we have at hand is square. If it is not we must decompose it into square triangles and proceed from there.

As it looks in the sketch (assuming i represented faithfully your given constrictions - 2xspeed, reaching the point simultaneously,...) the resulting triangle is irregular for all situations but the one in which the player is on 90 degree course (not represented) in relation to initial line of sight with the parting AI. Not all is lost because we can still decompose it into square triangles (black vertical lines).

If one finds the function which describes the line(curve) passing in all the P1, P2, for any arbitrary angle one needs only to find the intersection with that curve. If i am not mistaken (i am surprised at the result too) that curve passing in the Ps is a perfect ellipse (one would still need to find it's parameters -excentricity or small and big diameter). i am wrong.

The special case of 90 degrees is curious:

o = opposite, h = hypotenuse, a = adjacent

h = 2o

in which case

a^2 + o^2 = (2o)^2

(i am not saying that there isn't a shorter way to arrive at the solution)

Edited by gammadust

Share this post


Link to post
Share on other sites

gammadust: thanks, this is good.

I am thinking on using the law of cosines: b^2 = a^2 + c^2 - 2ac * cosBeta.

In my example b = 2a (because in the given time b travelled twice the distance of a, because of the 2x speed), so 2*a^2 = a^2 + c^2 - 2ac * cosBeta, where c is known, Beta is known, so I can get a, and it works for all situations. a is the length of travelled distance of unit1 until they meet.

Something like this. We'll see, won't we. :)

Anyhow, thanks for helping me gammadust, I appreciate it!

Share this post


Link to post
Share on other sites

glad that you shared the challenge too :)

(btw ignore the comment in regards to the curve being an ellipse, on second tought i should be wrong)

Share this post


Link to post
Share on other sites

:)

I now can't solve that equation to a=

Those college years were too long ago..

Share this post


Link to post
Share on other sites

Ok my trig is rubbish but

two units (starting at A and B, and whose distance, and speed I know

So A is the player, travelling in an ever changing direction at a ever changing speed.

To get B to meet up with A.

1. Place a point in the direction A is facing, the distance of A-B. This point is C.

2. RATIO equals distance of B-C divided by distance A-C.

3. The speed of A multiplied by RATIO equals the speed B needs to be travelling towards point C.

Repeat every frame/second and A and B will finally meet having travelled for the same amount of time.

Share this post


Link to post
Share on other sites

Good idea Larrow. I thought about it myself too. My idea is the optimized version of this, where not only speed, but distance is taken into account as well. (because speed is between tight limits. Sort of.)

So far it is working, but in the end kylania will be right: I am kinda shooting a sparrow with arty. But hey, I enjoy doing this. :D

Aaand I never knew the internet is full of online equation solvers!

Here is my final visualized solution:

https://docs.google.com/file/d/0BxjqGzmtx1GBU3ZWREpZNjU3OWs/edit?usp=sharing

The circles represent meeting points with different speed-ratios. The horizontal line is with equal speed.

The big circle above is 0.7x speed (northern unit is slower than southern).

The smaller ones are with 2x and 3x speed. (norhern unit is faster than southern unit.

Cool. This is good for Patriot missiles hunting down those Scuds too. :)

And here is the working formula for calculating the distance in player's current heading:

_a = (_dst*sqrt(_srat^2+cos(_beta)^2-1)-_dst*cos(_beta))/(_srat ^2-1);

_dst is A and B distance

_srat is their speed ratio (_a is highly dependant on it! Can't be 1, and anything below 1 can result in impossible results. The more the better)

_beta is the angle of player's heading and intercepting unit (direction difference)

Edited by zapat

Share this post


Link to post
Share on other sites
(because speed is between tight limits. Sort of.)
Of course, i mean if B is a soldier and the distance BC is greater than AC then B is never going to catch up if A is moving at full speed. The code in my last post is only going to work if B is an inanimate object that you can move the correct distance each evaluation.

The only trouble with Kylania's is that you need to know point C. You could add a waypoint to to a unit that is B and just change the waypoints position ever evaluation. Although changing a waypoints position to often seem to confuse the AI :D.

Ill add my little test mission here just for reference. Contains two objects, one is a helper object and one is a unit on a quadbike both trying to predict C of the player.

Red arrow is B, green arrow is B's predicted meeting point.

Pink arrow is the quadbike's predicted meeting point.

Share this post


Link to post
Share on other sites

Very glad you made it :)

But let me add this, you may find some optimizations:

If you always have Beta AND the ratio of velocities at any time, to make a correction in the direction you just need

HCZvqgZl.jpg

as surprising as it may seam you don't even need the distance!

Share this post


Link to post
Share on other sites

Is it THIS simple? :)

Thanks Gammadust, I owe you one...

Share this post


Link to post
Share on other sites
Is it THIS simple? :)

Thanks Gammadust, I owe you one...

I couldn't believe it either at first time. But you were the one to believe in a simple solution, i had already sidetracked myself onto the bushes despite some deal of enjoyment on the way :)

btw if by any chance you would still need the distances:

get angle gamma from y = 180 - alpha - beta

and lastly with the law of sines:

a / sin Alpha = c / sin Gamma = b / sin Beta

a = (c / sin Gamma) * sin Alpha

Share this post


Link to post
Share on other sites

I don't even know if this is Trigonometry, this is how bad it is :D Basically I'm trying to create and get 2 end points along a line for a flyby and could use some help.

 

Here is what I have so far.

 

I think the idea is correct its just the code is wrong

 

1 Get a random direction

2 Get the opposite direction

 

3 Get the middle point (e.g. a player but later a random pos) and get the positions of the end points 1.5k away of the player each direction

_dir1 = getDir random 360;
_dir2 = -(getDir _dir1);
_posA = [player, 1500, _dir1] call BIS_fnc_relPos; 
_posB = [player, 1500, _dir2] call BIS_fnc_relPos; 


_ambientFly = [_posA,_posB] call BIS_fnc_ambientFlyBy;

Share this post


Link to post
Share on other sites

_dir2 = _dir1 - 180;

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×