Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Check if line is straight

by jaredor (Deacon)
on May 16, 2011 at 13:46 UTC ( #905077=note: print w/ replies, xml ) Need Help??


in reply to Re: Check if line is straight
in thread Check if line is straight

In the original code, the slope is 0 for both horizontal and vertical lines, so you would have to first check for zero slope, then check for a stationary abscissa :-) to differentiate between horizontal and vertical. Personally, I would have made the slope undef for a vertical line, but it wouldn't make much difference in amount of coding effort.

I like the approach of LanX taking this out of the Cartesian setting and into vector notation; it generalizes all line orientations so that you don't have to specially handle edge cases. pajout has given the algebraic statement of the reasoning Re^2: Check if line is straight, which is good enough to answer what (we think) is the question, but it's good to keep the vector approach in mind.

As an erstwhile scientific programmer I still feel the need to point out that with floating point comparisons it might be a good idea to use a tolerance calculation somewhere....


Comment on Re^2: Check if line is straight
Re^3: Check if line is straight
by LanX (Canon) on May 16, 2011 at 17:18 UTC
    > As an erstwhile scientific programmer I still feel the need to point out that with floating point comparisons it might be a good idea to use a tolerance calculation somewhere....

    sure ... but I'm waiting pedagogically for the OP to come back before explaining how to get the correct angle out of the dot-product ;)

    Cheers Rolf

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://905077]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-08-23 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (176 votes), past polls