# Solver To determine if 3 points lie in a line

Algebra ->  Algebra  -> Points-lines-and-rays -> Solver To determine if 3 points lie in a line      Log On

 Ad: Algebra Solved!™: algebra software solves algebra homework problems with step-by-step help! Ad: Algebrator™ solves your algebra problems and provides step-by-step explanations!

 Geometry: Points, lines, angles, perimeter Solvers Lessons Answers archive Quiz In Depth

### Source code of 'To determine if 3 points lie in a line'

This Solver (To determine if 3 points lie in a line) was created by by chillaks(0)  : View Source, Show, Put on YOUR site
About chillaks: am a freelancer

 ==section input Enter the coordinates of 3 points lying on a plane: X1= *[input x1=1] Y1= *[input y1=1] X2=*[input x2=2] Y2=*[input y2=2] X3=*[input x3=3] Y3=*[input y3=3] To find if these points lies on a line. ==section solution perl my \$slope=((\$y2-\$y1)/(\$x2-\$x1)); my \$slope1=((\$y3-\$y1)/(\$x3-\$x1)); my \$slope2=((\$y3-\$y2)/(\$x3-\$x2)); if((\$slope==\$slope1) && (\$slope==\$slope2)) { print " The 3 points lie on a same plane. For all points to lie on a line they should satisfy the equation of a line. Hence any two points taken on a line should calculate to the same slope of a line. In order to prove the 3 points to lie on a line, as there exists a unique line containing three points and every line has a unique slope. Hence it will be sufficient to prove that the slope calculated taking 2 points at a time should be equal. Slope of line taking points (X1,Y1) and (X2,Y2) is {{{slope = (Y2-Y1)/(X2-X1)}}} {{{slope = ((\$y2-\$y1)/(\$x2-\$x1)) = \$slope}}} ........................(1) Slope of line taking points (X3,Y3) and (X1,Y1) is {{{slope = (Y3-Y1)/(X3-X1)}}} {{{slope = ((\$y3-\$y1)/(\$x3-\$x1)) = \$slope1}}} ........................(2) From conditions (1) and (2) The slopes are equal hence the 3 points can lie on same line. If the slope calculated from points (X2,Y2) and (X3,Y3) comes out to be same then it is confirmed that the 3 points lie on a same line. {{{slope = (Y3-Y2)/(X3-X2)}}} {{{slope = ((\$y3-\$y2)/(\$x3-\$x2)) = \$slope2}}} ........................(3) From (1),(2) and (3) Hence, It is proved that the 3 points lie on same line. To read more on equations of a line refer to articles on wikipedia " } else { print " The 3 points lie on a same plane. For all points to lie on a line they should satisfy the equation of a line. Hence any two points taken on a line should calculate to the same slope of a line. In order to prove the 3 points to lie on a line, as there exists a unique line containing three points and every line has a unique slope. Hence it will be sufficient to prove that the slope calculated taking 2 points at a time should be equal. Slope of line taking points (X1,Y1) and (X2,Y2) is {{{slope = (Y2-Y1)/(X2-X1)}}} {{{slope = ((\$y2-\$y1)/(\$x2-\$x1)) = \$slope}}} ........................(1) Slope of line taking points (X3,Y3) and (X1,Y1) is {{{slope = (Y3-Y1)/(X3-X1)}}} {{{slope = ((\$y3-\$y1)/(\$x3-\$x1)) = \$slope1}}} ........................(2) From conditions (1) and (2) The 3 points do not a same line. For all points to lie on a line they should satisfy the equation of a line. Hence any two points taken on a line should calculate to the same slope of a line. Here the slopes are unequal hence the points do not lie on same line. To read more on equations of a line refer to articles on wikipedia "; } ==section output slope1, ==section check x1=6 y1=6 x2=2 y2=2 x3=0 y3=0 slope=1