-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create digital differential analyzer_line.py #10929
Merged
Merged
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
c62f30a
Create DDA_line_drawing.py
nababuddin d08be9a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 220559a
Rename DDA_line_drawing.py to digital differential analyzer_line_draw…
nababuddin 5d4b127
Rename DDA_line_drawing.py to digital_differential_analyzer_line_draw…
nababuddin e8a0ab7
Update digital_differential_analyzer_line_drawing.py
nababuddin 1b621e1
Update digital_differential_analyzer_line_drawing.py
nababuddin 8391c5f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 70764bb
Update digital_differential_analyzer_line_drawing.py
nababuddin d84e4ec
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a6b452f
Update digital_differential_analyzer_line_drawing.py
nababuddin 06f87eb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7f2ee3c
Update digital_differential_analyzer_line_drawing.py
nababuddin f415328
Update digital_differential_analyzer_line_drawing.py
nababuddin 5cae215
Update digital_differential_analyzer_line_drawing.py
nababuddin 5234d02
Update digital_differential_analyzer_line_drawing.py
nababuddin f34960f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 842ad9e
Apply suggestions from code review
nababuddin 74b5dd1
Update and rename digital_differential_analyzer_line_drawing.py to di…
nababuddin dc1f4b2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 836ce48
Update digital_differential_analyzer_line.py
nababuddin 3aa73ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d9f2d33
Update digital_differential_analyzer_line.py
nababuddin a4dcebf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6d1844a
Update digital_differential_analyzer_line.py
nababuddin 67ca0e6
Update digital_differential_analyzer_line.py
nababuddin 94972ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9287725
Update digital_differential_analyzer_line.py
nababuddin b4b89ca
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6f0540d
Update digital_differential_analyzer_line.py
nababuddin 11e9315
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 93ed88b
Update digital_differential_analyzer_line.py
nababuddin ac7607e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7ce5261
Apply suggestions from code review
tianyizheng02 8dab7f4
Fix doctest
tianyizheng02 4a91773
Trigger GH workflows
tianyizheng02 6f381df
Fix function call in main block
tianyizheng02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
def dda_line(x1, y1, x2, y2): | ||
# Calculate the differences in x and y coordinates | ||
dx = x2 - x1 | ||
dy = y2 - y1 | ||
|
||
# Determine the number of steps to take | ||
steps = max(abs(dx), abs(dy)) | ||
|
||
# Calculate the increments for x and y | ||
x_increment = dx / steps | ||
y_increment = dy / steps | ||
|
||
# Lists to store the x and y coordinates of the line | ||
x_points = [x1] | ||
y_points = [y1] | ||
|
||
# Calculate and store the intermediate points | ||
x = x1 | ||
y = y1 | ||
for _ in range(steps): | ||
x += x_increment | ||
y += y_increment | ||
x_points.append(round(x)) | ||
y_points.append(round(y)) | ||
|
||
return x_points, y_points | ||
|
||
|
||
if __name__ == "__main__": | ||
# Input the coordinates of the two endpoints of the line | ||
x1 = int(input("Enter x1: ")) | ||
y1 = int(input("Enter y1: ")) | ||
x2 = int(input("Enter x2: ")) | ||
y2 = int(input("Enter y2: ")) | ||
|
||
# Calculate the points using DDA algorithm | ||
x_points, y_points = dda_line(x1, y1, x2, y2) | ||
|
||
# Plot the line using Matplotlib | ||
plt.plot(x_points, y_points, marker="o") | ||
plt.title("DDA Line Drawing Algorithm") | ||
plt.xlabel("X-axis") | ||
plt.ylabel("Y-axis") | ||
plt.grid() | ||
plt.show() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.