|
| 18 Dec 2011 06:22 AM |
I need to find out how big the area connecting 2 bricks is. I assume theyre bricks and not rotated weirdly.
I have the size of both of the faces, and the relative position of the other face.
To simplify it, think it in 1 dimension.
So we have 2 values and their radiuss. Find out how much they overlap.
The first value is in origin (its 0)
like position1=0 position2=4 radius1=2 radius2=3
those would overlap 1 unit.
k?
|
|
|
| Report Abuse |
|
|
| 18 Dec 2011 06:31 AM |
math.min(math.min(r1,r2)*2,math.abs(math.min(0,math.abs(p1-p2)-(r1+r2))))
Dat mah 50-tests-in-cmd-bar algorethm k? |
|
|
| Report Abuse |
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 18 Dec 2011 08:02 AM |
So you have two rectangles, and want to find the area of intersection?
That's actually really easy. Here's some python code. As of a few weeks ago, I like python.
class Rectangle(object): def __init__(self, x = 0, y = 0, width = 0, height = 0): self.left = x self.bottom = y self.width = width self.height = height @property def width(self): return self.right - self.left @width.setter def width(self, value): self.right = self.left + value @property def height(self): return self.top - self.bottom @height.setter def height(self, value): self.top = self.bottom + value @property def isValid(self): """Determine if a rectangle is valid, i.e. has positive dimensions""" return self.width >= 0 and self.height >= 0 @property def area(self): """Area of a rectangle""" return self.width * self.height def intersection(self, other): """Find the intersection of two rectangles. If no intersection, return an empty rectangle""" r = Rectangle() r.right = min(self.right, other.right) r.top = min(self.top, other.top) r.bottom = max(self.bottom, other.bottom) r.left = max(self.left, other.left) return r if r.isValid else Rectangle() #Declare the two rectangles r1 = Rectangle(0, 0, 20, 20) r2 = Rectangle(10, 5, 40, 5) #Area of intersection - prints 50 print r1.intersection(r2).area |
|
|
| Report Abuse |
|