Question

Help needed in python ! Classes can not be used ! Thanx

Many games have complex physics engines, and one major function of these engines is to figure out f two objects are colliding

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def ball_collide(b1, b2):
        (x1, y1, z1, r1) = b1
        (x2, y2, z2, r2) = b2
        
        dis = ((x1 - x2) ** 2 + (y1 - y2) ** 2 + (z1 - z2) ** 2) ** 0.5
        return dis < (r1 + r2)
        
fileName = 'tests.txt'
for l in open(fileName).readlines():
    b1, b2 = l.split(':')
    b1 = [int(x) for x in b1.split(',')]
    b2 = [int(x) for x in b2.split(',')]
    
    print('Test:', l, ' => ', ball_collide(tuple(b1), tuple(b2)))
    
    
    
    
/////////////////
tests.txt:
1,2,3,4:5,6,7,8

Files main.py 日 っ saved https://PassionateVerticalilnstructions.anjali 1 def ball_collide(b1, b2): D main.py (x1, yl, z1, r1)

Add a comment
Know the answer?
Add Answer to:
Help needed in python ! Classes can not be used ! Thanx Many games have complex...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Help needed related python task ! Thanx again How you're doing it • Write a function...

    Help needed related python task ! Thanx again How you're doing it • Write a function write_to_file() that accepts a tuple to be added to the end of a file o Open the file for appending (name your file 'student_info.txt') o Write the tuple on one line (include any newline characters necessary) o Close the file • Write a function get_student_info() that o Accepts an argument for a student name o Prompts the user to input as many test scores...

  • urgent Help needed in python program ! Thanx # This is a function definition. You can...

    urgent Help needed in python program ! Thanx # This is a function definition. You can ignore this for now. def parse_integer_list_from_string(string): """ Returns a list of integers from a string containing integers separated by spaces. """ # Split the line into a list of strings, each containing a number. number_string_list = string.split() # Create an empty list to store the numbers as integers. numbers = [] # Convert each string to an integer and add it to the list...

  • This is in Python Can I have some help? y =gt2 + yo with yo =...

    This is in Python Can I have some help? y =gt2 + yo with yo = 0 and g = 32 ft/s2, then we get y = 16t2 Write a program to perform the following tasks: • Create a "build Height” class • Create a function to calculate the height of the building Prompt the user to enter the measured time for the object to free fall from the top of the structure to the ground • Create three objects,...

  • C++ Addition of Complex Numbers Background Knowledge A complex number can be written in the format of , where and are real numbers.   is the imaginary unit with the property of .   is called the r...

    C++ Addition of Complex Numbers Background Knowledge A complex number can be written in the format of , where and are real numbers.   is the imaginary unit with the property of .   is called the real part of the complex number and   is called the imaginary part of the complex number. The addition of two complex numbers will generate a new complex number. The addition is done by adding the real parts together (the result's real part) and adding the...

  • IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand...

    IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand the Application The assignment is to first create a class calledTripleString.TripleStringwill consist of threeinstance attribute strings as its basic data. It will also contain a few instance methods to support that data. Once defined, we will use it to instantiate TripleString objects that can be used in our main program. TripleString will contain three member strings as its main data: string1, string2, and string3....

  • matlab INSTRUCTIONS Consider the spring-mass damper that can be used to model many dynamic systems Applying Newton...

    matlab INSTRUCTIONS Consider the spring-mass damper that can be used to model many dynamic systems Applying Newton's Second Law to a free-body diagram of the mass m yields the following ODE m습+8 +kx=F(t) (1) dt2 Where F() is a forcing function, Consider the case where the forcing function itself is a damped oscillation: Where F F(t)-Ae-Bt COS(wt) (2) For this activity we'll see how we can formulate this ODE for a solution using MATLAB that could be used to study...

  • Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in...

    Greeting! Kindly help me to solve my finals in PYTHON, I don't have a knowledge in PYTHON, new student. Please, please, I'm begging, Kindly answers all the questions. I'm hoping to grant my request. Thanks in advanced. 1.) What is the output of the following snippet? l1 = [1,2] for v in range(2): l1.insert(-1,l1[v]) print(l1)        a.) [1, 2, 2, 2]        b.) [1, 1, 1, 2]        c.) [1, 2, 1, 2]        d.) [1,...

  • Overview This assignment will give you experience on the use of classes. Understand the Application Every...

    Overview This assignment will give you experience on the use of classes. Understand the Application Every internet user–perhaps better thought of as an Internet connection–has certain data associated with him/her/it. We will oversimplify this by symbolizing such data with only two fields: a name ("Aristotle") and a globally accessible IP address ("139.12.85.191"). We could enhance these by adding other—sometimes optional, sometimes needed—data (such as a MAC address, port, local IP address, gateway, etc), but we keep things simple and use...

  • Assignment 4 Real Deal: Crier On Us Some word games, like Scrabble, require rearranging a combination of letters to make...

    Assignment 4 Real Deal: Crier On Us Some word games, like Scrabble, require rearranging a combination of letters to make a word. This type of arrangement is generally referred to as an anagram, it's known as a permutation in mathematics. This assignment will give you some experience thinking about and writing recursive functions. Write a C++ program that searches for ``anagrams'' in a dictionary. An anagram is a word obtained by scrambling the letters of some string. For example, the...

  • Lab 1.java only Goal: This lab will give you experience with defining and using classes and...

    Lab 1.java only Goal: This lab will give you experience with defining and using classes and fields, and with conditionals and recursive functions. Getting Started --------------- Read the Fraction.java class into a text editor and compile it filling in the command javac -g Fraction.java. The program should compile without errors. In a shell window, run the program using "java Fraction". The program should run, although it will print fractions in a non-reduced form, like 12/20. Part I: Constructors (1 point)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT