bresenham | simple implementation of Bresenham 's line drawing algorithm | Learning library

 by   encukou Python Version: 0.2.1 License: MIT

kandi X-RAY | bresenham Summary

kandi X-RAY | bresenham Summary

bresenham is a Python library typically used in Tutorial, Learning, Example Codes applications. bresenham has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can install using 'pip install bresenham' or download it from GitHub, PyPI.

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

            kandi-support Support

              bresenham has a highly active ecosystem.
              It has 35 star(s) with 13 fork(s). There are 2 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 0 open issues and 3 have been closed. On average issues are closed in 97 days. There are no pull requests.
              It has a positive sentiment in the developer community.
              The latest version of bresenham is 0.2.1

            kandi-Quality Quality

              bresenham has 0 bugs and 0 code smells.

            kandi-Security Security

              bresenham has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              bresenham code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              bresenham is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              bresenham releases are not available. You will need to build from source code and install.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi has reviewed bresenham and discovered the below as its top functions. This is intended to give you an instant insight into bresenham implemented functionality, and help decide if they suit your requirements.
            • Generator for bresenham
            Get all kandi verified functions for this library.

            bresenham Key Features

            No Key Features are available at this moment for bresenham.

            bresenham Examples and Code Snippets

            No Code Snippets are available at this moment for bresenham.

            Community Discussions

            QUESTION

            Line drawing algorithm in assembly
            Asked 2022-Mar-08 at 16:35

            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:35
            1. I 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.

            2. 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).

            3. 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:

            Source https://stackoverflow.com/questions/71390507

            QUESTION

            Bresenham's Algorithm Anti-aliased quadratic Bézier curve with line thickness
            Asked 2021-Sep-29 at 07:49

            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:49

            In 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:

            Source https://stackoverflow.com/questions/69362718

            QUESTION

            C/CPP - Converting floating point arithmetic to integer arithmetic
            Asked 2021-May-22 at 12:17

            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.

            Float Version ...

            ANSWER

            Answered 2021-May-22 at 12:17

            The floating-point code does four things with d:

            1. Initialize d to 2dy/dx−1, where dy and dx are ybya and xbxa, respectively.
            2. Evaluate whether d is greater than 0.
            3. Add 2dy/dx+2 to d.
            4. 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:

            1. Initialize d to 2dydx.
            2. Evaluate whether d is greater than 0dx (equal to 0).
            3. Add 2dy+2dx to d.
            4. 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.

            Source https://stackoverflow.com/questions/67649120

            QUESTION

            Bresenham line coding not drawing a line
            Asked 2021-May-19 at 19:56

            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:56

            I had double global variables which I didn't notice. Thank you all for your support.

            Source https://stackoverflow.com/questions/67264046

            QUESTION

            Algorithm behind score calculation in FAST corner detector
            Asked 2021-Apr-29 at 18:03

            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:03

            The 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:

            1. Get 16 pixel values on the circle centered at the target pixel
            2. 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)
            3. Take every pixel in the 16 as the beginning one of the step 2, and you will get 16 thresholds
            4. 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.

            Source https://stackoverflow.com/questions/67306891

            QUESTION

            Why the corners detected by Fast algorithm in OPENCV and my own implementation are not same?
            Asked 2021-Apr-28 at 13:29

            I have implemented a naive FAST corner detector using C++ boost algorithm. Currently it does not have non max suppression. I ran my implementation and the OPENCV implementation on this photo below

            The output of OPENCV is

            The output from my implementation is

            Here is my code

            ...

            ANSWER

            Answered 2021-Apr-28 at 13:29

            I can't compile your code. I can only spot a few random things, that might help you fix things:

            1. Your threshold_indicator array is sixteen elements, but your loops go to index 24 This will lead to Undefined Behaviour (unless the loop incidentally breaks before that point)

            2. valid_points_count is unused, yet it is being initialized to a magic number

            3. You 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.

            Source https://stackoverflow.com/questions/67297999

            QUESTION

            F# Bjorklund algorithm: convert while-loop to recursive function: type-constraint issue
            Asked 2021-Mar-28 at 01:27

            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:27

            You need to put parentheses around (bpat:list array). Otherwise the type annotation applies to bjork, not to bbpat:

            Source https://stackoverflow.com/questions/66836855

            QUESTION

            Buffered image inside a GUI
            Asked 2021-Mar-05 at 07:02

            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:01

            I 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.

            1. 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.

            2. 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.

            3. Use Swing layout managers. I used a GridBagLayout to create the control panel on the left. The GridBagLayout 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.

            Source https://stackoverflow.com/questions/66454377

            QUESTION

            Python using lamda function error missing 1 required positional argument: 'event'
            Asked 2021-Feb-15 at 16:22

            I have the following program

            ...

            ANSWER

            Answered 2021-Feb-15 at 15:21

            According 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.

            Source https://stackoverflow.com/questions/66210558

            QUESTION

            Why won't my Spaceship point toward the planet?
            Asked 2021-Jan-31 at 10:53

            Small gif showing problem but I don't have 10 reputation yet (this is only my 2nd question) and thus have to use link

            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:50

            Note, 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:

            Source https://stackoverflow.com/questions/65977749

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install bresenham

            python -m pip install bresenham. python -m pip install -e. To install without a virtual envitonment, add the ``--user`` option.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install bresenham

          • CLONE
          • HTTPS

            https://github.com/encukou/bresenham.git

          • CLI

            gh repo clone encukou/bresenham

          • sshUrl

            git@github.com:encukou/bresenham.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link