steffy john

Greenhorn

Posts: 25

posted 16 years ago

Hi all,

I have 6 x and y coordinates

x ="1237155.56788" y="198888.45678"

x ="1234556.55455" y="198745.67890";

x ="1267893.53467" y="195554.43321";

x ="1287600.34567" y="192311.34562";

x ="1277756.23456" y="198766.34567";

x ="1277766.45678" y="123455.56768";

Now I am having an original coordinate

x ="1258888.87655" y="123457.98765";

I have to write a function to select the 2 vertices between which the original coordinate exists:

How can I do this ?

any help, please

Stef

I have 6 x and y coordinates

x ="1237155.56788" y="198888.45678"

x ="1234556.55455" y="198745.67890";

x ="1267893.53467" y="195554.43321";

x ="1287600.34567" y="192311.34562";

x ="1277756.23456" y="198766.34567";

x ="1277766.45678" y="123455.56768";

Now I am having an original coordinate

x ="1258888.87655" y="123457.98765";

I have to write a function to select the 2 vertices between which the original coordinate exists:

How can I do this ?

any help, please

Stef

Jim Yingst

Wanderer

Sheriff

Sheriff

Posts: 18671

posted 16 years ago

To determine if three points are on the same line, check to see if the slop of a line connecting the first two points is the same as the slope of the line connecting the last two points. This would mean that

(y2 - y1) / (x2 - x1) == (y3 - y1) / (x3 - x1)

If this is true, then the three points are collinear. However this is complicated by roundoff error - the equation above will seldom be

((y2 - y1) * (x3 - x1)) / ((x2 - x1) * (y3 - y1)) == 1

And then do something like

Math.abs( ((y2-y1) * (x3-x1)) / ((x2-x1) * (y3-y1)) - 1) < 1e-10

to see if the values are "cloase enough" to a straight line.

Of course, this is just for three points. For your situation you will have to write some loops to consider all possible combinations of points, and check them each with the above test. Enjoy...

(y2 - y1) / (x2 - x1) == (y3 - y1) / (x3 - x1)

If this is true, then the three points are collinear. However this is complicated by roundoff error - the equation above will seldom be

*exactly*true. But you want to know if it is*close*to being true. You can rearrange the equation to get((y2 - y1) * (x3 - x1)) / ((x2 - x1) * (y3 - y1)) == 1

And then do something like

Math.abs( ((y2-y1) * (x3-x1)) / ((x2-x1) * (y3-y1)) - 1) < 1e-10

to see if the values are "cloase enough" to a straight line.

Of course, this is just for three points. For your situation you will have to write some loops to consider all possible combinations of points, and check them each with the above test. Enjoy...

"I'm not back." - Bill Harding, *Twister*