• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

get two coordinates

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 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...

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic