Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

2D VECTOR TRAVEL

Name: Anonymous 2011-05-21 14:17

Simple problem but i just cant find a nice sollution.

I have a two 2d points, the object starts at point 1 and travels to point 2 at some speed.

Also if it gets somewhat easier i also have the angle at which the object needs to travel.

Anyone can write something fast?

Name: Anonymous 2011-05-21 14:26

points are described by (x1, y1) and (x2, y2)
speed of travel is speed


xdist = x1 - x2
xdir = xdist / abs(xdist)
ydist = y1 - y2
ydir = ydist / abs(ydist)
totaldist = sqrt(xdist * xdist + ydist * ydist)
xfrac = xdist / totaldist
yfrac = ydist / totaldist
xspeed = xfrac * speed * xdir
yspeed = yfrac * speed * ydir


And then, at every timestep, add xspeed and yspeed to current x and y coordinates.

Name: Anonymous 2011-05-21 14:32

>>2
Thank you my good man will try it out

Name: Anonymous 2011-05-21 14:32

derp

Name: Anonymous 2011-05-21 14:34

Poster from #2 here—you should be able to figure this out on your own by age 16 just from taking high school trigonometry, or at the latest from first-year linear algebra at college.

Name: Anonymous 2011-05-21 16:23

I did these kind of problems in grade school science class. OP must be a retarded american.

Name: Anonymous 2011-05-21 21:18

>>5
>>6
The only way you can make yourself feel better about yourself.

Sad

Name: Anonymous 2011-05-21 21:20

WELL JUST FUCKING GET THE GODDAMN DERIVATIVES OF THE FUCKING VECTORS AND LOOP FOR X=1 TO THE LENGTH OF THE VECTOR ADDING THE DERIVATIVE EACH ITERATION, GODFUQIN DAMN

Name: Anonymous 2011-05-21 22:15

x += cos(angle) * speed
y -= sin(angle) * speed

Name: Anonymous 2011-05-21 22:33

>>9
In before someone complains about sin and cos considered harmful.

Also, degrees, radians, or 8-bit angles?

Name: Anonymous 2011-05-22 0:26

>>10
or 8-bit angles?
nintendians

Name: Anonymous 2011-05-22 1:21

>>11
I thought they were called Carmackians. (The Doom map format is built on them.)

Name: Anonymous 2011-05-22 9:14

>>10
use a 'lookup table' for sin and cos
http://en.wikipedia.org/wiki/Lookup_table

Name: Anonymous 2011-05-22 11:13

Computer Science is a BULLSHIT degree. Learn a manly trade, like ENGINEERING.

Don't change these.
Name: Email:
Entire Thread Thread List