HP Forums
(28S) three points are collinear ? - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (28S) three points are collinear ? (/thread-86.html)



(28S) three points are collinear ? - Damien - 12-14-2013 07:20 PM

FIRST METHOD:
Code:
« C→R 1 
   4 ROLL C→R 1 
   7 ROLL C→R 1 
   {3 3} →ARRY DET 
   ABS 1E-10 <
 »
'ALIG'

A(a,a'), B(b,B'), C(c,c') are lined up if the determinant = 0
|a a' 1|
|b b' 1| = 0
|c c' 1|


SECOND METHOD: (added 26/12/2013)
A(a,a'), B(b,B'), C(c,c') are lined up if the angle (AB,AC) = 0 modulo π (in radians)

Lets find the angle (AB,AC) first
Code:

«  3 PICK - 
   ARG 
   SWAP ROT -
   ARG -
   1 SWAP R→C
   P→R ARG
 »
'ANGL'

then
Code:

«  ANGL 
   2 *
   1 SWAP R→C
   P→R ARG
   ABS 1E-10 <
 »
'ALIG'

Examples:

3: (2,2)
2: (4,1)
1: (5,3)
ALIG
1: 0 (false)

3: (2,-3)
2: (4,1)
1: (5,3)
ALIG
1: 1 (true)