“Obróć wektor” Kod odpowiedzi

Obróć wektor 2D pod kątem

rotate vector (x1, y1) counterclockwise by the given angle
(angle in radians)

newX = oldX * cos(angle) - oldY * sin(angle)
newY = oldX * sin(angle) + oldY * cos(angle)
Clear Cat

Obróć wektor

function rotate(angle: number) {
        this.angle += angle
        this.x = Math.cos(this.angle) * this.length
        this.y = Math.sin(this.angle) * this.length
}
Himanshu Jangid

Obróć wektor pod kątem

var rotateVector = function(vec, ang)
{
    ang = -ang * (Math.PI/180);
    var cos = Math.cos(ang);
    var sin = Math.sin(ang);
    return new Array(Math.round(10000*(vec[0] * cos - vec[1] * sin))/10000, Math.round(10000*(vec[0] * sin + vec[1] * cos))/10000);
};
Thankful Trout

Odpowiedzi podobne do “Obróć wektor”

Pytania podobne do “Obróć wektor”

Więcej pokrewnych odpowiedzi na “Obróć wektor” w TypeScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu