Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Guido Italy
20
Years of Service
User Offline
Joined: 25th Dec 2005
Location:
Posted: 24th Jun 2014 12:44
Hi to all ,

Can you write a function
to calculate x, y of the intersection point
perpendicular to the two objects? (As attached)

I know:

x, y of the two objects and the angle of the two objects

Thanks and sorry for my Inglese!
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 24th Jun 2014 13:55 Edited at: 24th Jun 2014 13:58
I'm a little rusty, but here's the math behind it.

Note: Vectors are denoted as V=[x,y] where V.x=x and V.y=y.

For each object, you need a directional vector D and a position vector P. Since you have the angle of the object, that's easy enough to calculate using trigonometry:

D1 = [cos(a1), sin(a1)]
D2 = [cos(a2), sin(a2)]

Where a1 is the angle of object 1 and a2 is the angle of object 2, and D1 and D2 are both unit vectors.

The position vectors are obviously:

P1 = [a1x, a1y]
P2 = [a2x, a2y]

Where a1x and a1y are the 2D coordinates of object 1 and a2x and a2y are the 2D coordinates of object 2.

From this data, we can define two rays, R1 and R2:

R1(t1) = P1 + t1 * D1
R2(t2) = P2 + t2 * D2

Where t1 and t2 are unknown scalars indicating a single position along the ray, and R1 and R2 are position vectors.

The intersection point of the two rays exists when R1 and R2 are equal, i.e.

R1(t1) = R2(t2)

Which gives us the equation:

P1 + t1 * D1 = P2 + t2 * D2

Rearrange:

P1 - P2 = t2 * D2 - t1 * D1

Giving us a simultaneous linear equation:

P1.x - P2.x = t2 * D2.x - t1 * D1.x
P1.y - P2.y = t2 * D2.y - t1 * D1.y

To efficiently solve that, you can use conventional algebra, or you can do some fancy stuff and build a matrix and two vectors:

D = [[D2.x, -D1.x],[D2.y, -D1.y]]
T = [t2, t1]
P = P1 - P2

where:

P = D * T

If the matrix D is singular, i.e. its determinant is 0, it means there is no solution. Otherwise you can use the standard simultaneous linear equation method for solving both t1 and t2.



TheComet, what the frick is this frack??? you may be asking yourself at this point in time. Don't worry, here's some code. (This is untested because I don't have a DBP compiler. Let me know how it works. I'll test myself it when I get home.)



Guido Italy
20
Years of Service
User Offline
Joined: 25th Dec 2005
Location:
Posted: 24th Jun 2014 18:22
thank you very much !


Check when I get home!
Guido Italy
20
Years of Service
User Offline
Joined: 25th Dec 2005
Location:
Posted: 24th Jun 2014 18:50
Hi !

mmmm. I found aerror in the translation to DbPro

proble is Type/EndType

type Mat2x2 is not global and you have problem in Function

and ather problem that i not understand ... ( sorry and than )

Ciao , Guido

my mail is [email protected]
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 25th Jun 2014 01:25 Edited at: 25th Jun 2014 01:26
I accidentally switched t1 and t2.

Here's the unoptimised code (don't use this, this is only so you understand the math):


Since we only need t2, there's some stuff we can omit to make it faster:


Example:


Guido Italy
20
Years of Service
User Offline
Joined: 25th Dec 2005
Location:
Posted: 25th Jun 2014 13:31
Thank you !!
Guido Italy
20
Years of Service
User Offline
Joined: 25th Dec 2005
Location:
Posted: 25th Jun 2014 15:18
Hi Comet,

I tried your code now
I made some changes just to try better

In the attached picture you will see that there is a problem,

in the case of the figure should not respond with an intersection ...

Can you help me?

Thank , Guido
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 25th Jun 2014 15:32
Oh right, try changing this:


to this:


Guido Italy
20
Years of Service
User Offline
Joined: 25th Dec 2005
Location:
Posted: 25th Jun 2014 15:42
mmm. same problem intersection is detected ...
Guido Italy
20
Years of Service
User Offline
Joined: 25th Dec 2005
Location:
Posted: 25th Jun 2014 15:47
ps thank ...
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 25th Jun 2014 15:57
Really? Damn, I guess I suck at math. Does this work?



Add this line:


I'm at work so can't verify what I'm saying. It's got something to do with t2 and the determinant being greater than 0.

Guido Italy
20
Years of Service
User Offline
Joined: 25th Dec 2005
Location:
Posted: 25th Jun 2014 16:01
Ciao ,

still not ok,

No problem now I have to go back to work too!

Thank Guido

Ps This evening can i write you an e-mail ?
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 25th Jun 2014 16:26
No need for e-mails when we have this shiny forum.

Guido Italy
20
Years of Service
User Offline
Joined: 25th Dec 2005
Location:
Posted: 25th Jun 2014 21:34
... sorry any news ? ( thank )
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th Jun 2014 00:58
Made it better. New code:


Example:


Guido Italy
20
Years of Service
User Offline
Joined: 25th Dec 2005
Location:
Posted: 26th Jun 2014 15:19
Fantastic !

Is perfect !

Many many Thank !

Login to post a reply

Server time is: 2026-07-06 17:11:58
Your offset time is: 2026-07-06 17:11:58