Python 3 Geometry point position using functions Given a dir

Python 3

Geometry: point position using functions

Given a directed line from point p0(x0, y0) to p1(x1, y1), you can use the following condition to decide whether a point p2(x2, y2) is on the left of the line, on the right, or on the same line. p2 is on the left of the line. p2 is on the right of the line. p2 is on same line. write a program that prompts the user to enter the three points for p0, p1, and p2 and displays whether p2 is left of the line from p0 to p1, to the right, or on the same line. Here are some sample runs.

Enter the coordinates for the three points p0,p1,p2: 3.4, 2, 6.5, 9.5, -5.4
p2 is on the left side of the line from p0 to p1
ALSO need outprint for same line and on the right side

Functions

#Return true if point (x2,y2) is on the left side of the directed line from (x0, y0) to (x1,y1)
def leftOfTheLine(x0,y0, x1,y1,x2,y2):

#Return true if point (x2,y2) is on the same line from (x0, y0) to (x1,y1)
def OnTheSameLine(x0,y0, x1,y1,x2,y2):

#Return true if point (x2,y2) is on the line segment from (x0, y0) to (x1,y1)
def onTheLineSegement(x0,y0, x1,y1,x2,y2):

Solution

def leftOfTheLine(x0,y0,x1,y1,x2,y2):
    if((x2 - x1)*(y0 - y1) - (y2 - y1)*(x0 - x1)) > 0:
        print(\"Given point is to the left of other two points\")
      
def rightOfTheLine(x0,y0,x1,y1,x2,y2):
    if((x2 - x1)*(y0 - y1) - (y2 - y1)*(x0 - x1)) < 0:
        print(\"Given point is to the right of other two points\")
  
def OnTheSameLine(x0,y0,x1,y1,x2,y2):
    if((x2 - x1)*(y0 - y1) - (y2 - y1)*(x0 - x1)) == 0:
        print(\"All three points are on the same line\")

def onTheLineSegement(x0,y0,x1,y1,x2,y2):
    if (x1!=x2):
        if (x1<x0 and x0<x2)|(x1>x0 and x0>x2):
            print(\"All three point are on the same line segment\")
  
    elif(y1!=y2):
        if (y1<y0 and y0<y2)|(y1>y0 and y0>y2):
            print(\"All three point are on the same line segment\")
   
    else:
     print(\"First and second point are the same\")
  


if __name__ == \"__main__\":

    x1 = float(input(\"Enter first point x-coordinate x1: \"))
    y1 = float(input(\"Enter first point y-coordinate y1: \"))
    x2 = float(input(\"Enter second point x-coordinate x2: \"))
    y2 = float(input(\"Enter second point y-coordinate y2: \"))
    x0 = float(input(\"Enter point to be checked x-coordinate x: \"))
    y0 = float(input(\"Enter point to be checked y-coordinate y: \"))
  
    leftOfTheLine(x0,y0, x1,y1,x2,y2)
    rightOfTheLine(x0,y0, x1,y1,x2,y2)
    OnTheSameLine(x0,y0, x1,y1,x2,y2)
    onTheLineSegement(x0,y0, x1,y1,x2,y2)
  
  
   Example 1:

Enter first point x-coordinate x1: 1
Enter first point y-coordinate y1: 2
Enter second point x-coordinate x2: 3
Enter second point y-coordinate y2: 4
Enter point to be checked x-coordinate x: 5
Enter point to be checked y-coordinate y: 6
All three points are on the same line

Example 2:

Enter first point x-coordinate x1: 1
Enter first point y-coordinate y1: 1
Enter second point x-coordinate x2: 2
Enter second point y-coordinate y2: 2
Enter point to be checked x-coordinate x: 3
Enter point to be checked y-coordinate y: 4
Given point is to the left of other two points

Python 3 Geometry: point position using functions Given a directed line from point p0(x0, y0) to p1(x1, y1), you can use the following condition to decide wheth
Python 3 Geometry: point position using functions Given a directed line from point p0(x0, y0) to p1(x1, y1), you can use the following condition to decide wheth

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site