Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Math problem  (Read 942 times)

Kofthefens

  • Bay Watcher
  • Keep calm and OH GOD CAPYBARAS
    • View Profile
    • Marshland Games
Math problem
« on: June 09, 2012, 07:42:53 pm »

I have been programming a strategy game, and I have run into a problem. I made this diagram:
Spoiler:  Diagram (click to show/hide)

So how can I find Vx, Vy, Wx, and Wy?

In case you're wondering, I will use this for flanking (in the AI). An enemy warrior will be at point T, and the 2 flanking warriors will go to V and W. They don't approach from opposite sides so that they can be close enough to lend each other aid.

I hope I explained this well enough, and thanks in advance for the help.
Logged
I don't care about your indigestion-- How are you is a greeting, not a question.

The epic of Îton Sákrith
The Chronicles of HammerBlaze
My website - Free games

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Math problem
« Reply #1 on: June 09, 2012, 07:48:03 pm »

Given your description, you can't find it. There are 3 degrees of freedom (the location of 1 vertex or the center, and a third one to describe the orientation of the triangle) and you only fix 2 of them (via the location).It's possible to give a solution as function of the third degree of freedom, but no absolute values can be given.
Logged

Kofthefens

  • Bay Watcher
  • Keep calm and OH GOD CAPYBARAS
    • View Profile
    • Marshland Games
Re: Math problem
« Reply #2 on: June 09, 2012, 07:53:16 pm »

(the location of 1 vertex or the center, and a third one to describe the orientation of the triangle) and you only fix 2 of them (via the location). It's possible to give a solution as function of the third degree of freedom, but no absolute values can be given.

The angle the triangle is rotated at is a given. In this example it's 0 degrees, as line TV is horizontal.
Logged
I don't care about your indigestion-- How are you is a greeting, not a question.

The epic of Îton Sákrith
The Chronicles of HammerBlaze
My website - Free games

zombie urist

  • Bay Watcher
  • [NOT_LIVING]
    • View Profile
Re: Math problem
« Reply #3 on: June 09, 2012, 07:58:53 pm »

(V_x,V_y) = (30cos(Θ), 30sin(Θ))
(W_x,W_y) = (30cos(Θ+2ⲡ/3), 30sin(Θ+2ⲡ/3)
Logged
The worst part of all of this is that Shakerag won.

Lectorog

  • Bay Watcher
    • View Profile
Re: Math problem
« Reply #4 on: June 09, 2012, 08:01:24 pm »

Vx will be cos(angle)*30 ; Vy will similarly be sin(angle)*30 .
Wx will be sin(30-angle)*30 ; Wy will be cos(30-angle)*30 .
I did this all without paper, so I may not be correct. I think it is, though.
This is in degrees, too. I think zombie urist's is in radians, but I can't tell, given the pi symbol isn't appearing for me.
For the Ws I operated off of the angle between TW and the vertical; zombie urist's approach is different, but it might work.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Math problem
« Reply #5 on: June 09, 2012, 08:04:31 pm »

Oh, then it's simple. There are two options, the linear algebra approach and the single-dimensional algebra approach.

Assuming the angle is given by T in degrees and defined as the counterclockwise direction from the X-axis.

The linear algebra approach is pretty simple. We just take V' and W' as the known vectors of an unrotated triangle, relative to T' = (0,0) and then apply a rotation matrix R to them, finally transforming them back to world space by adding T.

V' = (30,0)*R
W' = (15,30)/sqrt(45)*R
R = [cos T, -sin T; sin T, cos T]
V = V'+T
W = W'+T

The single-dimensional algebra approach is slightly less straight-forward. It can be obtained by decomposing V and W into an X and an Y section and realizing they can be calculated using trigonometry. It yields the following expressions:

V = T + (30*cos T, 30*sin T)
W = T + (30*cos T+60, 30*sin T+60)
« Last Edit: June 10, 2012, 06:08:09 am by Virex »
Logged

Kofthefens

  • Bay Watcher
  • Keep calm and OH GOD CAPYBARAS
    • View Profile
    • Marshland Games
Re: Math problem
« Reply #6 on: June 09, 2012, 08:09:07 pm »

Thanks! Now to let the thread slowly slide into oblivion.
Logged
I don't care about your indigestion-- How are you is a greeting, not a question.

The epic of Îton Sákrith
The Chronicles of HammerBlaze
My website - Free games

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: Math problem
« Reply #7 on: June 09, 2012, 08:26:45 pm »

I'm going to go ahead and post the calculations I did, in easily typed words instead of symbols, so that anyone else that searches can go ahead and find it :D

Given a normalized direction vector for object T at position (Tx, Ty):

T's normalized direction vector will be denoted as dvT with x-component being dvTx and y-component dvTy. Same format for objects V and W.

also, inside of the cos and sin functions the values are in degrees not radians, so you would have to convert those over to radians.

V = (d*(cos(arccos(dvTx)+120), d*(sin(arcsine(dvTy)+120))

W = (d*(cos(arccos(dvTx)-120), d*(sin(arcsine(dvTy)-120))

(d) is the distance away from T that V and W have to be placed.

Hope that isn't horrible math or too much of an eyesore. Not sure how to make the nice looking symbols >.>
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.