Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions graphics/digital_differential_analyzer_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ def digital_differential_analyzer_line(
"""
Draws a line between two points using the DDA algorithm.

This algorithm works by calculating the dx (change in x) and dy;(change in y) and then iteratively

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After dy - ";" is put by mistake, maybe, so remove it or adjust accordingly.

steps along the dominant axis,incrementing the other axis by a fractional amount (the slope).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The algorithm actually steps along both axes simultaneously. The calculation of the increments ($X_{inc}$ and $Y_{inc}$) ensures that the coordinate along the dominant axis (the one with the larger $\Delta$) is guaranteed to change by exactly 1 unit (or $-1$) in each step, while the coordinate along the non-dominant axis changes by a fractional amount (the slope). The algorithm doesn't "step along" just the dominant axis; it increments both $x$ and $y$ in every single step.

It is notable for its simplicity but also for its main disadvantage:
it relies on floating-point arithmetic at every step, which is computationally slow.
It is generally outperformed by Bresenham's algorithm, which achieves
the same result using only integer-based math.

Args:
- p1: Coordinates of the starting point.
- p2: Coordinates of the ending point.
Expand Down