You say co-ordinates, but you only mention an X axis. Are you working in a 1 dimensional co-ordinate system, or is it a 2 or 3 (or more) dimensional system?

If you are working in more than one dimension, then you will find that an arbitrary point will rarely be exactly on an arbitrary line due to floating point precision issues. Instead you will need to test how close the point is to the line. There are a number of mathematical ways to do that. Off the top of my head an easy way would be to work out the area of the triangle composed of the point and lines's endpoints and then divide that by the line's length. That will give you half the distance of the point from the line.

If you are working in only one dimension then a simple numerical comparison should suffice:

say "point is on line" if( point_x >= line_start && point_x <= line_end )

In reply to Re: fast way of working with numerical positions by chrestomanci
in thread fast way of working with numerical positions by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.