2D Vector bullshit
1
Name:
Anonymous
2008-11-14 6:04
I've got 2 points (ie. X,Y vectors), and I need to find out the angle (degrees°) between them, so I can move an object which is at one of the points towards the other point.
How do I calculate the degrees plz???
41
Name:
Anonymous
2008-11-15 15:35
void Object_t::Move()
{
Accel.x = thrust * cos(DEG2RAD(headingDegs)); ?? OMG SO FUCKING OPTIMZIED!!!!!!!!!
Accel.y = thrust * sin(DEG2RAD(headingDegs));
Vector += Velocity;
}
42
Name:
Anonymous
2008-11-15 16:17
>>41
I KNOW RIGHT
I also forgot the
Velocity += Accel; line but eh, I only pasted what's necessary.
So how the piss do I calculate the headingDegs?
43
Name:
Anonymous
2008-11-15 19:13
44
Name:
Anonymous
2008-11-15 19:35
>>42
Here's what you do. Fuck that pansy ass cosine shit.
cos(x) = dot(X, Y)/(length(X)*length(Y))
x = arccos(dot(X, Y)/(length(X)*length(Y)))
There is the angle between the points. Blam. Read SICP.
45
Name:
Anonymous
2008-11-15 19:37
BTW if you dont know what dot and length are:
dot(X, Y) = X[1]*Y[1] + X[2]*Y[2]
length(X) = sqrt(X[1]*X[1] + X[2]*X[2])
Good day.
46
Name:
Anonymous
2008-11-16 9:14
OP here, finally got this shit working, thx guize l00l
47
Name:
noobular
2008-11-17 8:02
WAIT NO
It doesn't work when the target vector is to the left of my current position vector.
/** Move ()
*
* Move the object towards its vector.
*
*/
void Object_t::Move()
{
Velocity.x = thrust * cos(headingDegs);
Velocity.y = thrust * sin(headingDegs);
Vector += Velocity;
}
/** GetDegrees ()
*
* Set headingDegs based on Target vector.
*
*/
void Object_t::GetDegrees()
{
float dx, dy;
if (Target.y > Vector.y)
dy = Target.y - Vector.y;
else
dy = Vector.y - Target.y;
if (Target.x > Vector.x)
dx = Target.x - Vector.x;
else
dx = Vector.x - Target.x;
headingDegs = atan(dy / dx);
}
If I add this part to the end:
if (Target.x < Vector.x)
headingDegs -= DEG2RAD(180);
it will work for targets that are left & up, but not left & down. WHAT DO I DO LOL?
48
Name:
Anonymous
2008-11-17 8:08
>>47
This is why we
DONT HELP HIM!!! ;)
49
Name:
fairX the haxxor
2008-11-17 13:07
50
Name:
Anonymous
2008-11-17 13:36
51
Name:
Anonymous
2008-11-17 15:20
52
Name:
Anonymous
2008-11-18 5:05
get atan2 up all in that ho for the sign of your life
53
Name:
Anonymous
2008-11-18 5:33
54
Name:
Anonymous
2008-11-18 8:02
Why the fuck do you want the angle for this? Just normalize the delta between the two points to the speed you want.
P.S. And you still need 3 points to calculate an angle, saying the "angle between 2 points" is a fucking meaningless statement.
55
Name:
Anonymous
2008-11-18 9:28
>>54
Obviously,
he meant the angle between two vectors , dipshit.
56
Name:
Anonymous
2008-11-18 13:17
This problem is trivial given a mathematician.
57
Name:
Anonymous
2008-11-19 1:36
>>56
Not the useless ones I'm working with.
58
Name:
Anonymous
2009-03-06 7:49
Responder client closed ClientSock.
60
Name:
Anonymous
2010-11-26 13:19