Light Style© by Fisana

Jump to content


Photo

Where to share/upload random map generators


  • Please log in to reply
21 replies to this topic

#21 FeXoR

FeXoR

    Centurio

  • Community Members
  • PipPipPipPipPip
  • 903 posts

Posted 29 February 2012 - 04:58 PM

Of cause I mixed it up...
And forgot the area of definition that is only PI not 2*PI...

A function working and consistent to the unit placement orientation for getting the angle of a vector from one point towards another is for example (perhaps not the best):

// Function to get the direction from one point to another
function getDirection(point1, point2)
{
	var vector = [point2[0] - point1[0], point2[1] - point1[1]];
	var output = Math.acos(vector[0]/getDistance(point1, point2));
	if (vector[1] > 0) {output = PI + (PI - Math.acos(vector[0]/getDistance(point1, point2)))};
	return (output + PI/2) % (2*PI);
};


The other functions are correct...

Edited by FeXoR, 29 February 2012 - 05:03 PM.

  • 0

#22 FeXoR

FeXoR

    Centurio

  • Community Members
  • PipPipPipPipPip
  • 903 posts

Posted 29 February 2012 - 05:18 PM

Opened a new topic:
getDistance(point1, point2) and getDirection(point1, point2) from one point to another
  • 0