简体   繁体   English

在Erlang中查找形状重叠的功能

[英]Function to find shape overlapping in Erlang

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. 话虽如此,它们可以是2个重叠的圆或2个矩形,也可以是一个圆和一个矩形。 The only hint i got from Erlang documentation is to use abs() function. 我从Erlang文档中得到的唯一提示是使用abs()函数。

Any help greatly appreciated 任何帮助,不胜感激

This question is not quite related to Erlang. 这个问题与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. 您需要做一些作业,挖掘数学公式,然后设计一个算法,然后您可以回来,我们将帮助您在Erlang中实现该算法。

Here are some resources to get you started: 以下是一些入门资源:

A forum with some some useful links , especially the Geometry 2D Cookbook. 一个包含一些有用链接的论坛, 尤其是Geometry 2D Cookbook。 There are some related SO questions, like this one about PathGeometry , or this one about overlapping rectangles . 有一些相关的SO问题,例如关于PathGeometry的问题或关于重叠矩形的问题

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. 我还建议将问题重新发布到Stack Exchange https://math.stackexchange.com/的数学部分上,只需跳过有关Erlang的详细信息。 It's the algorithm you would need to know in the first place. 这是您首先需要了解的算法。

I hope that helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM