|
|
View previous topic :: View next topic |
Author |
Message |
Andrei
Joined: 26 Aug 2007 Posts: 3
|
Drawing the line on graphic lcd without endpoint coordinates |
Posted: Sat Oct 13, 2007 3:48 am |
|
|
I'm wondering is it possible to create a function that draws a line on 128*64 graphic lcd, when only startpoint coordinates and the angle are known. The endpoint coordinates are unknown so in theory the line will be endless.
e.g. line(60, 40, 0.78) //startpoint X, startpoint Y, angle in radians
will draw me something like this:
Code: |
--------------------------
| / |
| / |
| / |
| / |
| |
| |
--------------------------
|
|
|
|
Ttelmah Guest
|
|
Posted: Sun Oct 14, 2007 3:20 am |
|
|
Of course it is.
The best way, will depend on how the actual display functions are done, but (for example), one solution, it to simply plot the line to an imaginary point 'outside' the screen.
If you say that the largest line that will fit on the screen, is the diagonal of the screen, for your display, 143 pixels, then you can generate an 'imaginary' endpoint, by taking sin(theta)*143, and cos(theta)*143, adding these to the initial X and y coordinates, and using the resulting points, as the required 'endpoints' for the line to plot.
There are lots of alternative approaches (for example, taking the sin and cos, and working out which 'quadrant' the line would sit in, and then extrapolating it just to the edge of the screen), but generally line drawing algorithms using the Bressenham algorithm, will efficiently handle the line going off the screen, so the simple approach will work quite well.
Obviously, you can change the sign of the sin/cos results, and which value they are added to, to change where the effective 'origin' is for the angular measures.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|