78Views5Replies

Author Options:

Plot a diagonal line? Answered

PD17200,11600;
i am sure I should know this.

I need to plot a diagonal line from 17200 to 11600  Obviously there are more X points than Y points.

Is there a handy algorithm to work out how may X points to ploy against Y?

My current solution is to extract the difference - 5600 and divide the Y by that  11600/5600 = 2.1

So you plot 2.1 Y points for every X point. Somehow this seems wrong?

i am sure I should know this.

Discussions

0
None
steveastrouk

Best Answer 3 years ago

Look at "Bressenhams line drawing algorithm"

0
None
rickharris

3 years ago

Thanks for the answers guys, Let me amplify a little more just to satisfy everyone.

I have a CAD program that can output in HPGL. I want to see if I can translate the HPGL into x,y movement for a plotter/cutter using a PIC micro.

Ill use the information you have given me thanks.

Steve, have seen Bressenhams algorithm before and should have remembered - Thanks.

Jack, thanks for the maths reminder - I knew I should have known it.

0
None
rickharrissteveastrouk

Answer 3 years ago

So I see on reading it up. Now to try to convert it to some code. thanks.

0
None
Jack A Lopez

3 years ago

Your question does not make sense to me. I am guessing you want to draw a line in the xy plane.

Points in the xy plane are defined by pairs of two numbers. One of these numbers is the x part. The other is the y part.

For example (x1,y1) is a point in the xy plane.

Also (x2, y2) is a point in the xy plane.

The usual formula for a line, in the xy plane, is:

y = m*x + b

Suppose, I want to know the formula for a line which includes the two points I mentioned earlier, (x1,y1) and (x2, y2).

Both satisfy the formula for a line.

y1 = m*x1 + b
y2 = m*x2 + b

All that remains is to solve for m and b.

m = (y2-y1)/(x2-x1)
b = y1 - m*x1 = y2 - m*x2

Once you have an equation for your line, plotting the line should be easy.