-1

I am fairly new to functional paradigm so here is my question

I have a function that calculates the perimeter of a circle and a rectangle which works, here it is

perim({circle, {X,Y}, R}) -> 
math:pi()*(R * 2);
perim({rectangle, {X,Y}, H, W})-> 
  (H + W) * 2.

Now my question is how to define a function to test whether or not two shapes overlap. Having said that they can be 2 circles overlapping or 2 rectangles or a circle and a rectangle. The only hint i got from Erlang documentation is to use abs() function.

Any help greatly appreciated

Eilleen
  • 357
  • 1
  • 16

1 Answers1

4

This question is not quite related to Erlang. It's a mathematical problem. You need to do some homework, dig up mathematical formulas, then design an algorithm, and then you can come back and we will help you to implement the algorithm in Erlang.

Here are some resources to get you started:

A forum with some some useful links, especially the Geometry 2D Cookbook. There are some related SO questions, like this one about PathGeometry, or this one about overlapping rectangles.

I would also propose to repost the question on the mathematical part of Stack Exchange https://math.stackexchange.com/ , just skip the details about Erlang. It's the algorithm you would need to know in the first place.

I hope that helps.

Community
  • 1
  • 1
Greg
  • 8,230
  • 5
  • 38
  • 53