Welcome to the Parallax Discussion Forums, sign-up to participate.

pmrobert
Posts: **572**

I have a project where I have two sets of x/y coordinates each describing separate but definitely intersecting lines - e.g., (0,0 to 8,9) and (2,0 to 6,14). Does anyone have a non-math major friendly algorithm for solving for that intersection? Sadly, geometry and trig is a distant memory for all but things I do at least every few years. I have googled for a solution and have found solutions but they seem way too complex for something that perhaps is as simple as I think. Perhaps it does require multiple iterations, etc., just asking for input here. The application specifically is using 3 microphones in a triangular array to locate the X/Y coordinate of a brief, loud sound such as a projectile striking a coplanar piece of, for example, a thin piece of plywood upon which a target is affixed. I have the math and hardware working in successfully obtaining vectors for microphones A-B and B-C sound times of arrival. I also have another pair of microphones spaced a meter apart colinear with projectile path at 2 meters from the gun muzzle. These are for capturing projectile speed with the caveat that it probably only works for supersonic projectiles, the shock wave is shockingly easy to detect and has a very short rise time. Any help would be greatly appreciated. I'm using a Prop 1 and an ESP8266 communicating to a PC app for now but also have the P2 ES board working very nicely (love those fast ADCs!) but I'm waiting for production silicon until progressing further with the P2. Thanks for reading, I wanted to give a relatively complete picture of what I'm doing.

Mike R.

Mike R.

The difference between theory and practice is that, in theory, there is no difference between theory and practice, but in practice, there is.

## Comments

351You first need to convert the lines into "functions" of the form

y = (x*slope)+offset

which can be calculated as such (i think. sanity check before using):

slope = (y2-y1) /(x2-x1)

Note that lines parallel to Y can't be expressed, so there needs to be a special case. You might be able to get away with just using a very high slope.

offset = y1 - (x1*slope)

Now we can solve for the intersection:

(x*slope1)+offset1 = (x*slope2)+offset2(x*slope1)+offset1-offset2 = x*slope2offset1-offset2 = (x*slope2) - (x*slope1)offset1-offset2 = x*(slope2-slope1)(offset1-offset2) / (slope2-slope1) = xx = (offset1-offset2) / (slope2-slope1)

y = (x*slope1)+offset1

572Mike R.

6,386The terms can be computed first and then combined...

a = x1 - x2

b = y1 - y2

c = x3 - x4

d = y3 - y4

e = x1*y2 - y1*x2

f = x3*y4 - y3*x4

g = a * d - b * c

Then

Px = (e * c - a * f) / g

Py = (e * d - b * f) / g

Watch out for points that are close together. Subtractions in the denominator, the term "g", make the equation "stiff". Small errors in the representation of the numbers can make the result blow up if the points are close together. Need to maintain sufficient precision.

22,438-Phil

Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away.-Antoine de Saint-Exupery6,38615,396My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBladeProp OS(also see Sphinx, PropDos, PropCmd, Spinix)Website: www.clusos.comProp Tools (Index) , Emulators (Index) , ZiCog (Z80)22,438-Phil

Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away.-Antoine de Saint-Exupery8,326LOL, ditto.

Life is unpredictable. Eat dessert first.

15,396When I was in high school (60's), we used blackboard and chalk. No computers.

Most computers in the world were valve based, although transistor based computer were starting to take over. Terminals were TTY.

Would have been nice to see a pair of lines like that on a PC (or tablet) in color. You could zoom in and out to see the intersection, etc. Those nice parabola's that we had to draw could be on a screen, together with the area under a curve. Would have made my day to see those things when learning maths. We had no idea what i*i=-1 (i squared equals -1) was used for - that would come the following year as j*j=-1 with electronics. Wish i'd known what it was used for two years earlier as it would have made more sense, not that I didn't grasp it - maths was my best and favorite.

My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBladeProp OS(also see Sphinx, PropDos, PropCmd, Spinix)Website: www.clusos.comProp Tools (Index) , Emulators (Index) , ZiCog (Z80)1,494I gave up on that half long ago.........

1,304lol, carried the analog computer myself, but had to go to the lab to use the Friedan rotary calculator to do statistics!

Jim

15,396Ah, Friden. My mate in NZ has a few old Friden calculators that he has fixed and now run.

I cut my teeth on the Friden System Ten computer (later Singer and then ICL) System Ten). It was a mini, but that mini was the length of my garage. I need to find those old photos.

My Prop boards: P8XBlade2, RamBlade, CpuBlade, TriBladeProp OS(also see Sphinx, PropDos, PropCmd, Spinix)Website: www.clusos.comProp Tools (Index) , Emulators (Index) , ZiCog (Z80)773Propeller Tool 1.3.2, BASIC Stamp Editor 2.5.4, Javelin Stamp IDE x.x.x, Arduino IDE, PST

Hardware:

BASIC Stamp Board of Education, Propeller Board of Education, Propeller Project Board, Propeller Mini

572572Mike R.