whatdotcolor along a line connecting two points
Author |
Message |
Silinter
|
Posted: Wed Feb 04, 2009 11:49 pm Post subject: whatdotcolor along a line connecting two points |
|
|
my god, i've searched everywhere, to no avail, i can't even figure it out myself >.<
so, as title says, i would like to do whatdotcolor along a line connecting two points, with only the two connecting points being known.
please don't start telling me to use math collision detection; i've read richcash's tutorial.
it's quite possibly the most useful thing i've read relating to computer programming and collision detection; however, it's of no use in this situation.
i don't want to have to explain my program, but it should be enough to know that it involves checking the pixel color along a straight line connecting two points. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Thu Feb 05, 2009 12:47 am Post subject: RE:whatdotcolor along a line connecting two points |
|
|
A good place to start would be drawing a line using Draw.Dot. Think back to grade 10 (or earlier?) Math -- what is the function for a line?
y = mx + b (I think those are the letters... even though they are very undescriptive)
Loop over X, figure out Ys, draw your line. Now to check for the colour at every point, use the same set of X/Y pairs.
Though since one of the more recent versions of Turing make this kind of collision trivially simple with Math.DistancePointLine(), by the virtue of doing all the Math for you. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Silinter
|
Posted: Thu Feb 05, 2009 1:25 am Post subject: Re: whatdotcolor along a line connecting two points |
|
|
yeh, i've tried both y-y1=m(x-x1) and y=mx+b but i can't figure out the values.
what do you mean by looping over the x's and figuring out the y's? how do you know the x coordinates in the first place?
i initially tried to get some y values and figure out the x's using y-y1=m(x-x1) but i don't know either x or y.
how would you figure out at the x's on the line? |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Thu Feb 05, 2009 2:35 am Post subject: Re: whatdotcolor along a line connecting two points |
|
|
Silinter @ Thu Feb 05, 2009 1:25 am wrote: how would you figure out at the x's on the line?
Silinter @ Wed Feb 04, 2009 11:49 pm wrote: ...the two connecting points being known. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Silinter
|
Posted: Thu Feb 05, 2009 2:39 am Post subject: RE:whatdotcolor along a line connecting two points |
|
|
now you're just making me look stupid ;_; |
|
|
|
|
![](images/spacer.gif) |
andrew.
|
Posted: Thu Feb 05, 2009 5:30 pm Post subject: RE:whatdotcolor along a line connecting two points |
|
|
If you know the two points, then just find the slope using (y2 - y1)/(x2 -x1). The slope is rise over run, so make that number a fraction if it isn't already by putting it over 1. Then just take the numberator and go up by that much from the first point, and then use the denominator to go left or right. |
|
|
|
|
![](images/spacer.gif) |
OneOffDriveByPoster
|
Posted: Mon Feb 09, 2009 9:25 am Post subject: Re: whatdotcolor along a line connecting two points |
|
|
It should be easier to use parametric equations.
Point a: (ax, ay)
Point b: (bx, by)
Point along the line:
(ax + t(bx - ax), ay + t(by - ay))
For t between 0 and 1, you are looking at points in the line segment between Point a and Point b.
You can choose increments of t appropriately to step a certain distance no matter what the two points are. |
|
|
|
|
![](images/spacer.gif) |
Silinter
|
Posted: Mon Feb 09, 2009 4:31 pm Post subject: Re: whatdotcolor along a line connecting two points |
|
|
OneOffDriveByPoster @ Mon Feb 09, 2009 9:25 am wrote: It should be easier to use parametric equations.
Point a: (ax, ay)
Point b: (bx, by)
Point along the line:
(ax + t(bx - ax), ay + t(by - ay))
For t between 0 and 1, you are looking at points in the line segment between Point a and Point b.
You can choose increments of t appropriately to step a certain distance no matter what the two points are.
That it is, that it is, thanks everyone, gonna come in handy especially now that i'm focusing on the part of my game that needs this. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|