bresenham | simple implementation of Bresenham 's line drawing algorithm | Learning library
kandi X-RAY | bresenham Summary
kandi X-RAY | bresenham Summary
A simple implementation of Bresenham’s line drawing algorithm. See `the Wikipedia entry`_ for details on what that is. Note that this is a simple implementation. It is written in Pure Python (without e.g. numpy), so it is relatively slow. I found some beauty in combining the classic algorithm (whose ingenuity lies in using only integers – a constraint that isn’t really as relevant now) with a Python generator (a modern device that follows the spirit of “executable pseudocode”, abstracting away the output subroutine). I hope others can appreciate the code as well.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Generator for bresenham
bresenham Key Features
bresenham Examples and Code Snippets
Community Discussions
Trending Discussions on bresenham
QUESTION
I'm trying to create a line-drawing algorithm in assembly (more specifically Bresenham's line algorithm). After trying an implementation of this algorithm, the algorithm fails to work properly even though I almost exactly replicated the plotLineLow() function from this Wikipedia page.
It should be drawing a line between 2 points, but when I test it, it draws points in random places in the window. I really don't know what could be going wrong because debugging in assembly is difficult.
I'm using NASM to convert the program to binary, and I run the binary in QEMU.
...ANSWER
Answered 2022-Mar-08 at 16:35I see no video mode
just 80x25 text VGA mode (mode = 3) you set at start with
cls
so how can you render points? You should set the video mode you want assuming VGA or VESA/VBE see the link above.why to heck use VGA BIOS for point rendering?
that will be slooooooooow and I have no idea what it does when no gfx mode is present. You can render points by direct access to VRAM (at segment
A000h
) Ideal use 8/16/24/32bit video modes as they have pixels aligned to BYTEs ... my favorite is 320x200x256c (mode = 19) as it fits into 64K segment so no paging is needed and pixels are Bytes.In case you are using characters instead of pixels then you still can use access to VRAM in the same way just use segment
B800h
and chars are 16 bit (color and ASCII).integer DDA is faster then Bresenham on x86 CPUs since 80386
I do not code in NASM for around 2 decades and closest thing to line I found in my archive is this:
QUESTION
In the document found at http://members.chello.at/easyfilter/bresenham.html it walks through the process of creating curves based arround the Bresenham's Algorithm, and it ends with an algorithm to create anti-aliased thick lines, but how can this be aplied to the Quadratic Bezier Curves (the Anti Aliased version found on the same site)?
I tried change the plotQuadBezierSegAA function's last line to use the algorithm of the thick line, but obviously it did not worked as it is computing the other pixels one by one. (I changed from plotLineAA(x0,y0, x2,y2);
to plotLineWidth(x0, y0, x2, y2, wd);
)
I also tried to draw more curves slightly shifted until it had the wanted thickness, but it creates problems with the anti aliasing colors. (A for loop that shifted by the x and y step (xx and yy variables) and recursively called the plotQuadBezierSegWidth).
None of this tries actualy worked, so could please someone help me acomplish the thickness in this curves. (The algorithm so far is the one from plotQuadBezierSegAA found on that site).
Code for the shifting:
...ANSWER
Answered 2021-Sep-29 at 07:49In the scratchpad (js file here: http://members.chello.at/easyfilter/bresenham.js lines 909 to 1049) it uses the plotQuadRationalBezierWidth with the w set as 1 to compute a normal Bezier curve with a specified amount of width for the thickness of the line (the wd parameter).
The ported c code from the file:
QUESTION
I have the following c++ functions (implementing Bresenham's line algorithm), seen in the book
Computer Graphics From Pixels to Programmable Graphics Hardware By Alexey Boreskov, Evgeniy Shikin
One of the function uses floats, and due to their inefficiency the book has presented another function which uses integer arithmetic only.
I'm having trouble understading why are the two equivalent, and why are we using left shift <<
here, doesn't a<<1
simply multiply a
by 2?
Note: We assume the points A:(xa,ya)
and B:(xb,yb)
have integer values.
ANSWER
Answered 2021-May-22 at 12:17The floating-point code does four things with d
:
- Initialize
d
to 2dy/dx−1, where dy and dx areyb
−ya
andxb
−xa
, respectively. - Evaluate whether
d
is greater than 0. - Add 2dy/dx+2 to
d
. - Add 2dy/dx to
d
.
In floating-point, the division by dx may produce a non-integer. To avoid this, we transform the operations by multiplying everything by dx, yielding:
- Initialize
d
to 2dy−dx. - Evaluate whether
d
is greater than 0dx (equal to 0). - Add 2dy+2dx to
d
. - Add 2dy to
d
.
We can readily see that these four equivalent operations are implemented in the integer code except for 3. The integer code appears to add 2dy−2dx to d
. The integer code matches code shown in the Wikipedia page for Bresenham’s line algorithm. I suspect the +
in the floating-point version is an error in the book.
QUESTION
I tried to use the following code Bresenham line drawing but by OpenGL GLUT project. I have successfully run the code but no outcome result. I'm trying to draw to points between the two points p1(5,8) and P2(9,11). But seems have a problem with my for loop.
...ANSWER
Answered 2021-May-19 at 19:56I had double global variables which I didn't notice. Thank you all for your support.
QUESTION
How is the score for a detected corner is calculated in the FAST corner detector? I read the original paper "Machine Learning for High Speed Corner detection" but in the score calculation portion nothing is explicitly mentioned as to which N contiguous pixels they are referring at. Is it the N contiguous pixels that satisfy the corner criteria for that point? I also found the below link
https://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/AV1011/AV1FeaturefromAcceleratedSegmentTest.pdf that speaks of the FAST corner score computation . Also, I am not finding any correspondence between the score function described in this paper and the score calculation done by OPENCV for the bresenham circle of radius 3.
https://github.com/opencv/opencv/blob/master/modules/features2d/src/fast_score.cpp
The score has been calculated in the cornerScore<16> function in the above link. Besides these things, no other article explicitly talks about the FAST score calculation in Fast feature Detector. Can anyone kindly give me any insight on this?
N.B -I have also looked at the second paper "Faster and Better:A machine learning approach to corner detection" but it has no explicit mention about the score calculation.
...ANSWER
Answered 2021-Apr-29 at 18:03The docs online confused me too:
The score function is defined as: “The sum of the absolute difference between the pixels in the contiguous arc and the centre pixel”
I'm pretty sure OpenCV doesn't calculate score like that. If you patiently read the source code you mentioned, you will find that the function cornerScore<16>
is doing this:
- Get 16 pixel values on the circle centered at the target pixel
- Take a set of 9 contiguous pixels from the 16, calculate the absolute differences between the 9 pixels and the center one, and take the minimum (from 9 abs-diffs) value (which is called a threshold)
- Take every pixel in the 16 as the beginning one of the step 2, and you will get 16 thresholds
- Return the maximum threshold as the corner score
From this pipeline, you can see that the score OpenCV calculates is the maximum threshold that makes the target pixel a FAST-corner.
QUESTION
ANSWER
Answered 2021-Apr-28 at 13:29I can't compile your code. I can only spot a few random things, that might help you fix things:
Your threshold_indicator array is sixteen elements, but your loops go to index 24 This will lead to Undefined Behaviour (unless the loop incidentally
break
s before that point)valid_points_count
is unused, yet it is being initialized to a magic numberYou can reduce a lot of code by not repeating yourself quite as much. E.g your code for the following bit took 45 lines of code. That's >4x as much.
QUESTION
I’m doing the deep dive into f# finally. Long time c-style imperative guy - but lover of all languages. I’m attempting the Bjorklund algorithm for Euclidean Rhythms. Bjorklund: Most equal spacing of 1’s in a binary string up to rotation, e.g. 1111100000000 -> 1001010010100.
https://erikdemaine.org/papers/DeepRhythms_CGTA/paper.pdf
I initially based my attempt off a nice js/lodash implementation. I tried from scratch but got all tied up in old concepts.
https://codepen.io/teropa/details/zPEYbY
Here's my 1:1 translation
...ANSWER
Answered 2021-Mar-28 at 01:27You need to put parentheses around (bpat:list array)
. Otherwise the type annotation applies to bjork
, not to bbpat
:
QUESTION
I was thinking about making a GUI with a text input field, and on the right have a bufferedImage, which updates on the input i enter in the "console". Is it possible to have these two in the same GUI?
What I was thinking about was this example:
I've made a code where I only have a bufferedImage, but I want to add the left part of the image above, and I'm a bit stuck on how?
...ANSWER
Answered 2021-Mar-05 at 00:01I created the following GUI as a basis for what you want to accomplish.
The two valid commands are "line" and "circle". The application generates random endpoints for a line and a random center point and radius for a circle.
So, here are the important points that I want you to take from the code I'm going to post.
Always start your Swing application with a call to the
SwingUtilities
invokeLater
method. This method ensures that your Swing components will be created and executed on the Event Dispatch Thread.Create an application model using plain Java getter / setter classes. I used this model to keep all the commands typed, so I could reproduce the drawing.
Use Swing layout managers. I used a
GridBagLayout
to create the control panel on the left. TheGridBagLayout
is not the easiest layout to learn, but it's one of the most flexible.
Here's the complete runnable code. I made all the classes inner classes so I could paste this code as one block. Generally, you put separate classes in separate files.
QUESTION
I have the following program
...ANSWER
Answered 2021-Feb-15 at 15:21According to your definition of button1_clicked
, it has mandatory event
parameter. But nothing is passed during a method call. Either you remove it, or make it optional through assignment a default value.
QUESTION
I have a simple test program with a Spaceship which is supposed to point toward a planet, but it points in odd directions instead.
The purpose of the program is to test whether my test program can get the angle from the spaceship to the planet, so an alternate method won't work, since I need the angle to determine which direction to apply "gravity" in (which is what this test is for).
This is also why the script repeats multiple times but only the final angle will be graphically displayed.
My program uses code gotten from SO question Calculate angle (clockwise) between two points
The answer by "Chris St Pierre" just gave me an error for attempting to divide a float by zero (?).
The answer by "ali_m" just gave me a problem like this one.
I'm using the answer by "Colin Basnett", which doesn't work for me either, but it's my favorite method so far because it doesn't require plugins (and because it's short and doesn't just straight-away throw an error at me).
I adapted it into the function below:
...ANSWER
Answered 2021-Jan-31 at 10:50Note, Pygame provides the pygame.math.Vector2
class. It is not necessary to paint 100 images of the space ship with different angles. You can rotate an image with pygame.transform.rotate
. See How do I rotate an image around its center using PyGame?.
The vector from the point (x0
, y0
) to the point (x1
, y1
) is:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install bresenham
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page