#! /usr/bin/env python # def line_exp2imp_2d ( p1, p2 ): #*****************************************************************************80 # ## LINE_EXP2IMP_2D converts an explicit line to implicit form in 2D. # # Discussion: # # The explicit form of a line in 2D is: # # ( P1, P2 ) = ( (X1,Y1), (X2,Y2) ). # # The implicit form of a line in 2D is: # # A * X + B * Y + C = 0 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 25 October 2015 # # Author: # # John Burkardt # # Parameters: # # Input, real P1(2,1), P2(2,1), two points on the line. # # Output, real A, B, C, the implicit form of the line. # from sys import exit # # Take care of degenerate cases. # if ( p1[0] == p2[0] and p1[1] == p2[1] ): print ( '' ) print ( 'LINE_EXP2IMP_2D - Fatal error!' ) print ( ' P1 = P2' ) print ( ' P1 = %g %g' % ( p1[0], p1[1] ) ) print ( ' P2 = %g %g' % ( p2[0], p2[1] ) ) exit ( 'LINE_EXP2IMP_2D - Fatal error!' ) a = p2[1] - p1[1] b = p1[0] - p2[0] c = p2[0] * p1[1] - p1[0] * p2[1] norm = a * a + b * b + c * c if ( 0.0 < norm ): a = a / norm b = b / norm c = c / norm if ( a < 0.0 ): a = -a b = -b c = -c return a, b, c