Add a rotate function

This commit is contained in:
2023-09-05 19:00:29 -07:00
parent 632561d0a2
commit 6adeef0283

View File

@ -19,6 +19,14 @@ class vector {
this.x += other_vector.x; this.x += other_vector.x;
this.y += other_vector.y; this.y += other_vector.y;
} }
rotate(rad) {
var cos = Math.cos(rad);
var sin = Math.sin(rad);
//this.x = Math.round(10000*(this.x*cos-this.y*sin))/10000;
//this.y = Math.round(10000*(this.x*sin+this.y*cos))/10000;
this.x = this.x*cos-this.y*sin;
this.y = this.x*sin+this.y*cos;
}
} }
class node { class node {