The Daily Click ::. Forums ::. Klik Coding Help ::. Getting the point between two crossed lines
 

Post Reply  Post Oekaki 
 

Posted By Message

traugott.simon



Registered
  23/08/2008
Points
  91
4th February, 2009 at 17:43:37 -

Hi!

Simple question:
Is it possible to get the exact point between two crossing actives (simple lines)?

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
4th February, 2009 at 17:49:43 -

example?

 
n/a

traugott.simon



Registered
  23/08/2008
Points
  91
4th February, 2009 at 18:09:43 -

you need an example from me?

lets say two lines cross. both different actives. i need to get the coordinates of the point, where these lines cross.

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
4th February, 2009 at 18:20:23 -

i know what you mean. but your wording or your thinking is off. actives are not lines. actives have a single x and a singe y coordinate. lines (technically line segments) have AT LEAST two coordinates (x1, y1) - (x2, y2).

 
n/a

traugott.simon



Registered
  23/08/2008
Points
  91
4th February, 2009 at 18:37:37 -

yes ok u r right. i have to use actives, so there should be a way to detect overlapping pixels. i´m not sure if this is possible, i guess not.

 
n/a

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
4th February, 2009 at 19:02:48 -

If you can know with certainty where the Active Object lines begin and end, its possible to determine through math where they intersect.


If you had the Hot Spot at one end of the line and the Active Spot at the other end, then you could retrieve these in the expression editor to find out the coordinates of each side of the line. From these coordinates, you can plug them into an equation to find the intercept of two straight lines.

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
4th February, 2009 at 20:32:18 -

Job done
http://cid-b1e7ee094271bbda.skydrive.live.com/self.aspx/Public/intercept.mfa

Don't ask me to explain - if you want to know how it works, Google "calculate intercept two lines" or something like that.

Edited by Sketchy

 
n/a

traugott.simon



Registered
  23/08/2008
Points
  91
4th February, 2009 at 20:49:14 -

well sketchy thats exactly what i needed! now i hope i understand your code and can use it for my project! thx alot

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
4th February, 2009 at 21:25:02 -

Okay, I will give a brief explanation after all...

It's all based on the formula of a straight line...
y = (m*x) + c

First, calculate "m" for each line. "m" is the slope, and is calculated using a little trigonometry...
m = (sin(angle) * -1) / cos(angle)

Next, calculate "c" for each line. "c" is the intercept, and is calculated by rearranging our original formula so...
c = y - (m*x)

Now, we know that...
y = (m1*x) + c1
y = (m2*x) + c2

So where the two lines intersect...
(m1*x) + c1 = (m2*x) + c2

A bit more algebra later and we find that...
x = (c2 - c1) / (m1 - m2)

Now we know "x", we can use it to solve our original formula for one of the lines...
y = (m1*(c2 - c1) / (m1 - m2)) + c1

 
n/a

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
4th February, 2009 at 21:39:04 -

aw sketchy beat me two it.

actually pretty spiffy using the angle to get the slope. that way you DONT have to have both ends of the line. you do however have to check whether the two actives are overlapping. otherwise it will give you a spot somewhere off in the distance.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click