Recent

Author Topic: Drawing y = ax + b line in paintbox  (Read 2671 times)

xamax2000

  • Newbie
  • Posts: 4
Drawing y = ax + b line in paintbox
« on: March 22, 2018, 10:15:08 am »
Hello,

I'm writing a program in which the user can draw a circle and a line and the program will calculate the points at which they intersect for you. The user can fill in the a and b for the y = ax + b line and then press a button so that it should be drawn onto the paintbox. The problem is, is that I don't know how I can draw this line with Paintbox.Canvas.Line(). Does anyone know a smart way to do this? The paintbox is 600 by 600.

Greetings,

Xamax

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: Drawing y = ax + b line in paintbox
« Reply #1 on: March 22, 2018, 11:18:36 am »
Did you read the documentation?  And don't forget to define the Pen and the Brush! ;D
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

balazsszekely

  • Guest
Re: Drawing y = ax + b line in paintbox
« Reply #2 on: March 22, 2018, 02:14:56 pm »
@xamax2000

Try attached project.

Homework: Calculate then draw the intersection points.
« Last Edit: March 22, 2018, 02:41:38 pm by GetMem »

xamax2000

  • Newbie
  • Posts: 4
Re: Drawing y = ax + b line in paintbox
« Reply #3 on: March 22, 2018, 10:49:10 pm »
Thanks for the code you wrote!
Although I didn't really use much of what you wrote, it brought me to an idea.
Because the paintbox is 600 by 600, I can simply use this:
If a = 0 then begin;
Paintbox1.Canvas.Line(0,bt,600,bt);
end

Else begin
Paintbox1.Canvas.Line(0,300*at + bt,600,-300*at + bt);
end;
Now it works perfectly.
Thanks a lot!

balazsszekely

  • Guest
Re: Drawing y = ax + b line in paintbox
« Reply #4 on: March 23, 2018, 06:41:51 am »
Quote
Now it works perfectly.
Really? I don't believe you  :D
Code: Pascal  [Select][+][-]
  1. If a = 0 then begin; //<--remove ";"
  2.   Paintbox1.Canvas.Line(0,bt,600,bt);
  3. end
  4. Else begin
  5.   Paintbox1.Canvas.Line(0,300*at + bt,600,-300*at + bt);
  6. end;

xamax2000

  • Newbie
  • Posts: 4
Re: Drawing y = ax + b line in paintbox
« Reply #5 on: March 23, 2018, 08:52:39 am »
Ah wait it didn't really work for every line.
I believe this is correct though:
  If a = 0 then begin;
  Paintbox1.Canvas.Line(0,bt,600,bt);
  end

  Else begin
  Paintbox1.Canvas.Line(0,300 + 300*at + bt,600,300 -300*at + bt);
  end;
But of course this only works if it is 600 by 600.
Also before this I have stated that bt := round(-b), because if the y coördinate gets higher, the line will go lower so this needs to be turned around.
« Last Edit: March 23, 2018, 09:45:56 am by xamax2000 »

 

TinyPortal © 2005-2018