Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!