generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How would i do this?

Previous Thread :: Next Thread 
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
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
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
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 is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
18 Dec 2011 07:05 AM
[ Content Deleted ]
Report Abuse
NXTBoy is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image