Home  >  Article  >  Web Front-end  >  Oblique 45 degree pathfinding implementation function_javascript skills

Oblique 45 degree pathfinding implementation function_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:47:591672browse

It’s easy to write a pathfinder.

Copy the code The code is as follows: x1, y1) {//Rectangular coordinates tilted 45 degrees
var x0 =0;
var y0 =0;
var s=-Math.PI/4;
var o={} ;
o.x = int((x0 x1*Math.cos(s) y1*Math.sin(s))) dx;
o.y =-int((y0 x1*Math.sin(s)-y1 *Math.cos(s)))/2 dy;
return o;
}
function rot45(x1, y1) {//45 degree oblique rotation to rectangular coordinates
var x0 =0;
var y0 =0;
x1-=dx
y1-=dy
y1*=-2;
var s=-Math.PI/4;
var o= {};
o.x = int((x0 x1*Math.cos(s) y1*Math.sin(s))/dw);
o.y = int((y0 x1*Math.sin(s) -y1*Math.cos(s))/dw);
return o;
}


Just give me a picture, 8 directions, you can change 4 directions
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn