Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Check if line is straight

by jaredor (Priest)
on May 16, 2011 at 13:46 UTC ( [id://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....

Replies are listed 'Best First'.
Re^3: Check if line is straight
by LanX (Saint) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://905077]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-03-29 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found