Page 1 of 1
Thsi code is acting weirdly...
Posted: Sat Nov 06, 2010 3:09 pm
by zac352
I tested the maths on wolfram|alpha. It came out fine... But when I run it in love, it returns a number around 91 every time.
When I tried it with different lines, it came out to -0,-0 every time. The line should have intersected at -300,-250.
Code: Select all
function intersect(x1,y1,x2,y2,x3,y3,x4,y4)
-- d = r_1*t + r_2*t
-- d = (r_1+r_2)t
-- d/t = r_1+r_2
-- t = d/(r_1+r_2)
print("Line 1:",x1,y1,x2,y2)
print("Line 2:",x3,y3,x4,y4)
local d=magnitude(x4-x1,y4-y1)
print("Dist:",d)
local r1,r2=math.abs((y2-y1)/(x2-x1)),math.abs((y4-y3)/(x4-x3))
print("Slopes:",r1,r2)
local r=r1+r2
print("Slope:",r)
local y=d/r
local x=r1*y
print(x,y)
return x,y
end
Re: Thsi code is acting weirdly...
Posted: Sat Nov 06, 2010 3:20 pm
by Robin
Wow. Cryptic naming for the win.
What was the W|A query you used?
Re: Thsi code is acting weirdly...
Posted: Sat Nov 06, 2010 3:24 pm
by zac352
Robin wrote:Wow. Cryptic naming for the win.
What was the W|A query you used?
solve d=r_1*t + r_2*t for t
I used that because if you think about it, line intercepts are similar to the questions that are like "Two trains leave stations traveling towards each other. One is going 100 km/h and the other is going 150 km/h. They are 1000 km away. When will they meet up?"
1000 = 100t + 150t
1000 = 250t
1000/250 = t
t = 4
Re: Thsi code is acting weirdly...
Posted: Sat Nov 06, 2010 4:56 pm
by bmelts
There are lots of extant resources on the internet. I recommend
http://local.wasp.uwa.edu.au/~pbourke/g ... ineline2d/
(Also, it's really not like that train problem at all, as the trains are directly across from and heading directly towards each other, whereas the two lines you're trying to find the intersection point of are (generally) not.)
Re: Thsi code is acting weirdly...
Posted: Sat Nov 06, 2010 5:22 pm
by Robin
anjo wrote:(Also, it's really not like that train problem at all, as the trains are directly across from and heading directly towards each other, whereas the two lines you're trying to find the intersection point of are (generally) not.)
Actually, I'd say it is. If you take horizontal to mean location and vertical to mean time, for example.
Re: Thsi code is acting weirdly...
Posted: Sat Nov 06, 2010 5:26 pm
by bmelts
Yeah, but that... that... uh...
Shut up.
Re: Thsi code is acting weirdly...
Posted: Sat Nov 06, 2010 8:58 pm
by zac352
anjo wrote:There are lots of extant resources on the internet. I recommend
http://local.wasp.uwa.edu.au/~pbourke/g ... ineline2d/
(Also, it's really not like that train problem at all, as the trains are directly across from and heading directly towards each other, whereas the two lines you're trying to find the intersection point of are (generally) not.)
Substitute y as time, and slope as rate. It works.
Robin wrote:anjo wrote:(Also, it's really not like that train problem at all, as the trains are directly across from and heading directly towards each other, whereas the two lines you're trying to find the intersection point of are (generally) not.)
Actually, I'd say it is. If you take horizontal to mean location and vertical to mean time, for example.
Exactly my point.