Explain how you would write a python program that takes a rectangle and a point in a 2D space as command-line arguments and checks if they intersect.

We first need to read the user input. We can decide to enter the coordinates in one line or multiple lines, separated by spaces or commas. There are different ways of doing it. We choose to enter the rectangle first with the x and y coordinates of each vertex separated by a space. Then, we will enter the x and y coordinates of the point. So, for a rectangle ABCD and a point P we will have:$ python xA yA xB yB xC yC xD yD xP yP This way, in Python we will have 10 arguments corresponding to the 10 values.To check if the point is in the triangle, we compute the area of the rectangle (ABC + ACD). We then compute the area (PAB + PBC + PCD + PAD). If the two areas are equal, then the point is in the rectangle. Otherwise, it is not intersecting with the rectangle.

NS
Answered by Nabil S. Python tutor

1318 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Using the shared code editor, write a recursive function for calculating a factorial of an input parameter.


What is the difference between using range() and a list of values?


Write a function that takes an imput (call it usr_in), the user's age (usr_age) and the user's name (usr_nm) and outputs the following string: "Hi, My name is [usr_nm], I am [usr_age] years old, and my favorite number is [usr_in]"


Write a program that takes a value x and then outputs x Fibonnaci numbers. E.g. if x=6 output would be 1 1 2 3 5 8


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences