Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

300
Vistas
Algoritma DDA (Digital Diferential Analyzer)

I have a program in JavaScript, but I can't display the graph points like (2,1), (3,2), (4,2), (5,3), (6,4), (7,4), (8,5).

function dda(x1, y1, x2, y2) {
  var dx = x2 - x1;
  var dy = y2 - y1;


  if (Math.abs(dx) > Math.abs(dy)) {
    var step = Math.abs(dx);
  } else {
    var step = Math.abs(dy);
  }
  var x_inc = dx / step;
  var y_inc = dy / step;



  var x = x1;
  var y = y1;
  for (var k = 1; k < step; k++) {
    x = x + x_inc;
    y = y + y_inc; //I'm confused about this part

  }
  return x;

}
console.log(dda(2, 1, 8, 5));

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to collect x and y values.

Beside this, you need to start with k = 0 and increment the values after using the values.

function dda(x1, y1, x2, y2) {
    const
        dx = x2 - x1,
        dy = y2 - y1,
        step = Math.abs(dx) > Math.abs(dy)
            ? Math.abs(dx)
            : Math.abs(dy),
        x_inc = dx / step,
        y_inc = dy / step,
        result = [];

    for (let k = 0, x = x1, y = y1; k < step; k++) {
        result.push([x, y]);
        x += x_inc;
        y += y_inc;
    }

    return result;
}

console.log(dda(2, 1, 8, 5));
.as-console-wrapper { max-height: 100% !important; top: 0; }

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda