[Server]Help needed in Vector

Started by KAKAN, Mar 08, 2016, 05:49 PM

Previous topic - Next topic

KAKAN

One of my friends asked this to me:
QuoteI can't seem to figure this one out with squirrel. We got two points:

(x0, y0, z0) & (x,y,z). (x0, y0, z0) is the point the player is standing on and (x,y,z) is the point r units infront of the player. I want to calculate (x,y, z). I remember this formula from multivariable calculus.

x = x0 + r*sin(a) *cos(b)
y= y0 + r*sin(a)*sin(b)

Where a is the angle between the Z-axis & the point (x,y,z) and b the angle between the X-axis and the projection on the (x,y, z0) plane. I tried testing the formula out by having z0 = z & b = player.Angle so that the angle a becomes pi/2 (sin (a) = 1). It didn't work. I've also tried converting the player.Angle to degree's & that didn't seem to work either. I have made many attempts to trying to figure this out and I just can't seem to find the problem. Maybe it has something to do with the player.Angle or something else that I haven't thought of. I would really appreciate some help if you got time & if something is unclear please let me know.
That guy isn't registered on this forum. I can't help him because I don't know what that sin or cos or something else does. I haven't read them in my school yet. Any help would be appreciated.
oh no

Thijn

#1
Credits to Juppi and his Ramp Spawning script for LU: http://forum.liberty-unleashed.co.uk/index.php/topic,398.0.html
function GetForwardPoint( pos, angle ) // you must pass an angle in degrees
{
                local x = pos.x, y = pos.y;
local x2 = x + 1.0 * cos(angle) - 25.0 * sin(angle);
local y2 = y + 1.0 * sin(angle) + 25.0 * cos(angle);
                return Vector( x2, y2, pos.z );
}

Stormeus

The player angle is already in radians so rad shouldn't require conversion.

Thijn

Quote from: Stormeus on Mar 08, 2016, 06:22 PMThe player angle is already in radians so rad shouldn't require conversion.
Edited

KAKAN

Okay, that guy asked me another question, answer this one too :P
QuoteI checked the answers I am going to test this myself but I suspect that the first part of x & y with 1.0*sin(angle) or 1.0*cos(angle) is not needed. It's very little compared to 25.0*sin(angle) since sin(angle) & cos(angle) maximum value is 1. I also assume the distance = 25.0 units. I tried putting 5 & 2 as the position for 25.0 instead and it didn't work. But when I removed the 1.0*sin(angle) or 1.0*cos(angle) it worked on lower distances which is suspect is because the 1.0*sin(angle) or 1.0*cos(angle) part can't be neglected for smaller distances & isn't noticeable for longer distances.

If everything I said here is true and I am not saying it is until I fully test it myself, but then why would the y be equal to y0 + Distance*Cos(Angle) and x equal to x0 + Distance* ( - sin(Angle) ) when in a normal coordinate system it would be:

x = x0 + distance*cos(Angle)
y= y0 + distance*sin(Angle)

Is the coordinate system in VC-MP different or am I totally wrong?
oh no

ysc3839

Quote from: KAKAN on Mar 10, 2016, 08:26 AMOkay, that guy asked me another question, answer this one too :P
QuoteI checked the answers I am going to test this myself but I suspect that the first part of x & y with 1.0*sin(angle) or 1.0*cos(angle) is not needed. It's very little compared to 25.0*sin(angle) since sin(angle) & cos(angle) maximum value is 1. I also assume the distance = 25.0 units. I tried putting 5 & 2 as the position for 25.0 instead and it didn't work. But when I removed the 1.0*sin(angle) or 1.0*cos(angle) it worked on lower distances which is suspect is because the 1.0*sin(angle) or 1.0*cos(angle) part can't be neglected for smaller distances & isn't noticeable for longer distances.

If everything I said here is true and I am not saying it is until I fully test it myself, but then why would the y be equal to y0 + Distance*Cos(Angle) and x equal to x0 + Distance* ( - sin(Angle) ) when in a normal coordinate system it would be:

x = x0 + distance*cos(Angle)
y= y0 + distance*sin(Angle)

Is the coordinate system in VC-MP different or am I totally wrong?
Could use a picture to describe the question?

Stormeus

Quotex = x0 + distance*cos(Angle)
y= y0 + distance*sin(Angle)

This sounds like it should be correct to me for finding a point at a given distance. Juppi's function uses distance constants optimized for ramp spawning.