Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

222
Visualizações
How to move an angle closer to another angle?

If I have an angle theta (radians), a small angle delta (radians) and a target angle theta prime (radians), how can I increment/decrement theta by delta such that it would move closer to the angle theta prime? The goal is to push it closer and eventually reach and equal theta prime (but not go past it). It should work for negative radians or radians that are above Math.PI or lower than -Math.PI.

something like this

function MoveTheta(theta, delta, theta_prime) {
    // magic to move theta by at most delta closer to theta_prime
    return new_theta_value;
}

I would keep calling MoveTheta until MoveTheta equals theta_prime. How could this be written?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

function MoveTheta(theta, delta, theta_prime) {
    // find the distance between theta and theta_prime
    var diff = theta_prime - theta;
    
    // find the number of times you need to add/subtract delta to theta in order
    // to get to theta_prime (without passing theta_prime)
    var deltas = Math.floor(diff / delta);
    
    var new_theta_value = theta + deltas * delta;
    return new_theta_value;
}

Is this what you're looking for?

about 4 years ago · Juan Pablo Isaza Relatório

0

You can try the following solution:

First evaluate the distance from the target angle . Then if the distance is less than the step return the target angle or the original angle plus the step multiplied by the sign of the difference to take into account the direction of the rotation.

function move(
theta, // the original angle
delta, // the step
theta_prime // the target angle
)
{

    const diff = theta_prime - theta; 

    return Math.abs(diff) > delta ? tetha + Math.sign(diff) * delta : tetha_prime;
}

if the result of this method is equal to the target angle than the procedure is complete.

function move(theta, delta, theta_prime) {
const diff = theta_prime - theta;
return Math.abs(diff) > delta ? theta + Math.sign(diff) * delta : tetha_prime;

}

let theta = 75;
const delta = 4;
const theta_prime = 32;

while (theta != theta_prime) {
theta = move(theta, delta, theta_prime);
console.log(theta);
}

console.log("done");

about 4 years ago · Juan Pablo Isaza Relatório

0

Unless you don't care about usage of trig. functions, try the next approach (should solve problems with transition over zero, choose shortest direction etc):

rot = atan2(cos(th)*sin(th_pr)-cos(th_pr)*sin(th), 
            cos(th)*cos(th_pr)+sin(th_pr)*sin(th))
if rot >= 0 
      new_th = th + min(delta, rot)     
else
      new_th = th + max(-delta, rot)     
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda