The stupid question is the question not asked PerlMonks

### Re^2: Check if line is straight

by jaredor (Priest)
 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....

Replies are listed 'Best First'.
Re^3: Check if line is straight
by LanX (Bishop) 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

Create A New User
Node Status?
node history
Node Type: note [id://905077]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2018-05-24 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
World peace can best be achieved by:

Results (179 votes). Check out past polls.

Notices?