• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 419
  • Last Modified:

How to extend a line starting from (x0,y0) and passing thru (x1,y1) upto (xn,yn)?

Hi,

I have one center point (x0,y0) and some more points scattered on canvas (x1,y1), (x2,y2)...
I want to show a motion of a sprite in a straight line starting from (x0,y0) thru (x1,y1) till it reaches beyond the boundary of canvas.

In fact, the sprite might be present anywhere on canvas (x1,y1/x2,y2...) and from a central reference point (x0,y0) i want to show its motion in straight line till it reaches beyond the canvas boundary.

Many line drawing (pixel-by-pixel) algorithms give coordinates from x0,y0 to x1,y1 and not beyond that, however, i want to extend that line to (xn,yn) which could be anything depending upon (x0,y0) and (x1,y1)

Any ideas?
Algorithm?
line-extend-problem.gif
0
vijaywadnere
Asked:
vijaywadnere
  • 2
  • 2
1 Solution
 
ozoCommented:
x = X0 + (X1-X0)*t
y = Y0 + (Y1-Y0)*t
0
 
vijaywadnereAuthor Commented:
Ozo:
Though I somehow calculated the value for "t" that suits my requirements by hit-n-trial - and the value i get is t>1 & t<2 (1.09/1.1/1.2..) what exactly this value should be?
What this "t" denotes??

The formula works like charm for any pixel in any quadrant.
0
 
vijaywadnereAuthor Commented:
Even though the "t" remained mystery for me, I accept this solution since I managed to get my work done with the help of the given formula.

A little explanation would have claimed a higher grade.
0
 
ozoCommented:
Sory, I didn't see your question,
t goes from 0 to 1 between the points, and then beyond 1 to extend the line
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now