Jump to content

trigonometry, need 2 functions


adsad2

Recommended Posts

Posted

I'm not good in trigonometry and need these functions to the script, preferably in pure mathematics.

Determining point given a point, distance and direction

(x, y, z, distance, direction)

Speed in one direction (find x, y-speed)

(direction, speed)

As said, I'm not good in trigonometry, I am very grateful for the help.

Thanks in advance.

PS. sorry for bad English, using automatic translation

Posted

Please help me, I need the features of the script and can not figure out how I can make them. :(

It seems that it is easy for anyone who can trigonometry?

Posted
I'm not good in trigonometry and need these functions to the script, preferably in pure mathematics.

Determining point given a point, distance and direction

(x, y, z, distance, direction)

Speed in one direction (find x, y-speed)

(direction, speed)

As said, I'm not good in trigonometry, I am very grateful for the help.

Thanks in advance.

PS. sorry for bad English, using automatic translation

Function #1:

  
function relativePoint(x, y, dist, angle) 
  
    local a = math.rad(90 - angle); 
  
    local dx = math.cos(a) * dist; 
    local dy = math.sin(a) * dist; 
  
    return x+dx, y+dy; 
  
end 
  

I assume this is what you wanted. If I understood you correctly you can just use the same function for the second question too, if you put 0 for x and y and just use the distance and angle/rotation arguments.

Posted

Thanks robhol, it works fine!

But I need another function. I write the prototype here and hope someone can help me

find the angle rotation from the points (x1, y1), (x2, y2)

if a ped was on point 1 and I set x to this value the ped would look toward point 2.

Sorry my English ...

Posted
math.deg(math.atan2(x2-x1,y2-y1)) 

I think this should work, but you may have to negate it (put - at the start of the line) or swap x1 with x2 and y1 with y2.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...