Home > Web Front-end > JS Tutorial > body text

Oblique 45 degree pathfinding implementation function_javascript skills

WBOY
Release: 2016-05-16 18:47:59
Original
1673 people have browsed it

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
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template