In Python, can I write a function that takes objects as inputs and performs different calculations depending on the types of the objects?
For example, say I have two classes: "circle" and "line". I define a circle object A with a radius and centre position, and a circle object B with a different radius and centre position. I then define a line object C with a direction vector and a point along the line.
I would like to write a function that calculates the intersection:
def intersect(obj1,obj2):
# Returns intersection of two geometric entities
If I input the two circles A and B, I want the function to return the area of intersection of A and B. But if I input circle A and line C, I want the output to be the points (if any) where the line crosses the circle. So intersect(obj1,obj2) will need to somehow read the class of obj1 and obj2, and act accordingly.