?
Solved

Start-Endpoint

Posted on 2001-06-23
13
Medium Priority
?
309 Views
Last Modified: 2010-04-06
Hello. Ok, I know the startpoint (0,0) and the endpoint (233,417). So first:
Canvas.Moveto(0,0);
Canvas.Lineto(233,417);
Now I need to know all the different points between (0,0) and (233,417). I want to put them in a array.
Any suggestions?
0
Comment
Question by:zerotwo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 3

Expert Comment

by:f15iaf
ID: 6221709
you have the canvas.pixels[x,y] array and if canvas is in bitmap it's even better because you have scanline property which you can copy directly to array
0
 
LVL 6

Assisted Solution

by:zebada
zebada earned 200 total points
ID: 6221871
Take a look at (winAPI) LineDDA() function - it calls back each time it draws a pixel and you can then save the pixel's x,y location on each call back.
I've not used it but I'm sure it does what you want.
0
 
LVL 4

Accepted Solution

by:
DMN earned 200 total points
ID: 6221950
Zebada is right. Here is a sample:

{===================== PAS =====================}
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure MyLineDDA(x,y:integer;lparam:TStrings); stdcall;
begin
  lparam.add(inttostr(x)+','+inttostr(y));
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  LineDDA(0,0,100,175,@MyLineDDA,integer(Memo1.Lines));
end;

end.

{===================== DFM =====================}
object Form1: TForm1
  Left = 192
  Top = 107
  Width = 544
  Height = 375
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Memo1: TMemo
    Left = 20
    Top = 16
    Width = 261
    Height = 269
    ScrollBars = ssVertical
    TabOrder = 0
  end
end

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:AvonWyss
ID: 6222467
zerotwo, if you want to computer the points of a line yourself (that is, without the help of Windows and the callback), you can do it with a floating point routine (easier to understand) or using the bresenham algorithm (the standard for line drawing, using only integers).

Link for bresenham explanation:
http://www.gamedev.net/reference/articles/article767.asp
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6222921
That is the Pascal source i found for Bresenham.
Quite old isn't it? Works perfect.
I use it to smooth a mouse movement.

{BEGIN:  BRESENHM.TXT       8 30-May-88    48   512  Textfile }
PROGRAM Bresenham;

  PROCEDURE DrawPixel (x,y:  INTEGER);
  BEGIN
    WRITELN ('(x,y) = (',x:3,',',y:3,')')
  END {DrawPixel};

  PROCEDURE DrawLine (xStart,yStart, xEnd,yEnd:  INTEGER);
  {Bresenham's Line Algorithm.  Byte, March 1988, pp. 249-253.}
    VAR
      a,b        :  INTEGER;  {displacements in x and y}
      d          :  INTEGER;  {decision variable}
      diag_inc   :  INTEGER;  {d's increment for diagonal steps}
      dx_diag    :  INTEGER;  {diagonal x step for next pixel}
      dx_nondiag :  INTEGER;  {nondiagonal x step for next pixel}
      dy_diag    :  INTEGER;  {diagonal y step for next pixel}
      dy_nondiag :  INTEGER;  {nondiagonal y step for next pixel}
      i          :  INTEGER;  {loop index}
      nondiag_inc:  INTEGER;  {d's increment for nondiagonal steps}
      swap       :  INTEGER;  {temporary variable for swap}
      x,y        :  INTEGER;  {current x and y coordinates}
  BEGIN {DrawLine}
    x := xStart;              {line starting point}
    y := yStart;
    {Determine drawing direction and step to the next pixel.}
    a := xEnd - xStart;       {difference in x dimension}
    b := yEnd - yStart;       {difference in y dimension}
    {Determine whether end point lies to right or left of start point.}
    IF   a < 0                {drawing towards smaller x values?}
    THEN BEGIN
      a := -a;                {make 'a' positive}
      dx_diag := -1
    END
    ELSE
      dx_diag := 1;
    {Determine whether end point lies above or below start point.}
    IF   b < 0                {drawing towards smaller x values?}
    THEN BEGIN
      b := -b;                {make 'a' positive}
      dy_diag := -1
    END
    ELSE
      dy_diag := 1;
    {Identify octant containing end point.}
    IF   a < b
    THEN BEGIN
      swap := a;
      a := b;
      b := swap;
      dx_nondiag := 0;
      dy_nondiag := dy_diag
    END
    ELSE BEGIN
      dx_nondiag := dx_diag;
      dy_nondiag := 0
    END;
    d := b + b - a;            {initial value for d is 2*b - a}
    nondiag_inc := b + b;      {set initial d increment values}
    diag_inc    := b + b - a - a;
    FOR i := 0 TO a DO BEGIN   {draw the a+1 pixels}
      DrawPixel (x,y);
      IF   d < 0               {is midpoint above the line?}
      THEN BEGIN               {step nondiagonally}
        x := x + dx_nondiag;
        y := y + dy_nondiag;
        d := d + nondiag_inc   {update decision variable}
      END
      ELSE BEGIN               {midpoint is above the line; step diagonally}
        x := x + dx_diag;
        y := y + dy_diag;
        d := d + diag_inc
      END
    END;
    WRITELN;
    READLN
  END {DrawLine};

BEGIN
  DrawLine (0,0, 10,  4);
  DrawLine (0,0,  4, 10);
  DrawLine (0,0, -4, 10);
  DrawLine (0,0,-10,  4);
  DrawLine (0,0,-10, -4);
  DrawLine (0,0, -4,-10);
  DrawLine (0,0,  4,-10);
  DrawLine (0,0, 10, -4)
END {Bresenham}.

{END:  GRAPH:BRESENHAM.TEXT  }
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6224388
robert_marquart, the age of an algorithm does not make it fall apart ;-)

Anyways, the URL I posted does include a full, well-explained Pascal source sample also. It may be easier to understand due to the comments and explanations than the one posted above.
0
 

Author Comment

by:zerotwo
ID: 6228856
Well,I agree with AvonWyss, but maybe I can use it still...
By the way DMN, if you could document your sample code, so that even I can understand it, you would deserve the points... but first I have to check out if it works.
Maybe we need to split points!?!?!
0
 

Author Comment

by:zerotwo
ID: 6228862
Is BRESENHAM some sort of a Delpi/Pascal supercoder??
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6229262
Bresenham is a smart guy who "invented" (or discovered) a quick and smart method of calculatin all points along a line on the screen using only integers. He has also designed a very efficient circle and (as modificationof it) ellipse algorithm. It is independent of the used programming language.

DMN's solution is very simple: he uses a Windows function (LineDDA) which calls a given procedure for every position where a dot would be drawn on the line.
0
 

Author Comment

by:zerotwo
ID: 6241129
Ok I decided to accept the answers of zebada and DMN because they are quite easy to implement and answer the question "Now I need to know all the different points between (0,0) and (233,417)." much better then the rest of the comments. That's why I'm going to split points for zebada and DMN. zebada gave the basic information and DMN made an example, so each gets 50. Please wait, until points are splitted.
THX
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6426429
zerotwo, please have these points split as you promised to do. Thank you.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8685308
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

To be split between zebada and DMN

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question