Thsi code is acting weirdly...

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Thsi code is acting weirdly...

Post 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. :huh:

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
Hello, I am not dead.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Thsi code is acting weirdly...

Post by Robin »

Wow. Cryptic naming for the win.

What was the W|A query you used?
Help us help you: attach a .love.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Thsi code is acting weirdly...

Post 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
Hello, I am not dead.
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: Thsi code is acting weirdly...

Post 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.)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Thsi code is acting weirdly...

Post 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.
Help us help you: attach a .love.
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: Thsi code is acting weirdly...

Post by bmelts »

Yeah, but that... that... uh...

Shut up. :x
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Thsi code is acting weirdly...

Post 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.
Hello, I am not dead.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests