123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|736|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Concept/Design -> Connecting Lines

Mon, 21 Apr 2008, 08:37
Jayenkai
A while ago, I posted this..


Today when I came to use it, I realised that it was missing an important feature.
The function will check two lines, and if they connect it'll tell you so.
(hit 1 to move point one with the mouse, 2 to move point 2, and on up to point 4....)

What I'd like it to do, though, is find out WHERE they connect..

So, a puzzle..

What are the co-ords at point #5.

You can either have 2 globals "MeetX,MeetY" and get the function to place them in there, or have 2 versions of the function to each get X and Y results..
... The easier one would be the 2 globals method..

I'm sure there's a really really easy way to do this, but my brains slightly melted, today, so I can't seem to figure it out.

-=-=-
''Load, Next List!''
Mon, 21 Apr 2008, 10:52
shroom_monk
The first thing that comes into my head when I think of this is an equation. If you know the equation for the two lines, you could use an equation to figure it out. Well, at least on paper - I'm not sure about how you'd program it!

But say you knew that Line 1 was y=2x+5 and Line 2 was y=x+10, you could say:
2x+5=x+10
2x=x+5
x=5

Then, since x=5, y=(2*5)+5, so y=15.
Thus, the co-ords of Point 5 are (5,15).

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Mon, 21 Apr 2008, 10:56
Jayenkai
Hmm.. That kinda makes sense.
I'm not sure how I can get that to work in Blitz, but..
...

I'll have a think whilst at work!

-=-=-
''Load, Next List!''
Mon, 21 Apr 2008, 11:25
Forklift_Fred
I think your answer could be HERE but again, you'd need to translate it to code...

I tried but seem to have failed:


(Replaces the If collision... "Wow! That worked" line)

Probably got some brackets in the wrong place or referenced the wrong coordinates... I'll try again later

|edit| Add this little snippet to show the line coordinates...

|edit|


-=-=-
Come rain or shine...
Mon, 21 Apr 2008, 12:20
JL235
I just wrote this which should help to do some of what Shroom describes.

Enjoy!
Mon, 21 Apr 2008, 12:32
Forklift_Fred
OK, I copied the X1...X4 as set out in the Wiki page and it works. A little inaccurate due to pixel resolution but it works:



So, substituting Jay's coord(x,y) array...


So the full working example is thus:





(Having compared the code side by side, my original post failed because it was multiplying in one place where it should have been subtracting! - The middle of the top line in the Wiki equation)

-=-=-
Come rain or shine...
Mon, 21 Apr 2008, 12:43
Jayenkai
Wow! what a lot of maths!
I'll assume that's right.. Can't check at work, no Blitz.
Thanks guys!

(Now to hope it'll keep up to speed!)

-=-=-
''Load, Next List!''
Mon, 21 Apr 2008, 14:42
Jayenkai
Woot! Thanks Forklift, and both DD and Shroom, too.

Tomorrow, more work on the super secret game that involves lines colliding!!

-=-=-
''Load, Next List!''
Mon, 21 Apr 2008, 15:03
Forklift_Fred
It's Ghostbusters isn't it?

Don't cross the streams!

-=-=-
Come rain or shine...
Mon, 21 Apr 2008, 21:12
Orion Pax
Wow!...What a reference Fred! Havent heard that in a long time....
Thu, 24 Apr 2008, 07:18
Andy_A
Here's a fast lines intersect function.