Search Results

Search found 338 results on 14 pages for 'rectangles'.

Page 1/14 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Algorithms for positioning rectangles evenly spaced with unknown connecting lines

    - by MacGyver
    I'm new to game development, but I'm trying to figure out a good algorithm for positioning rectangles (of any width and height) in a given surface area, and connecting them with any variation of lines. Two rectangles will never have more than one line connecting them. Where would I begin working on a problem like this? This is only a 2 dimensional surface. I read about graph theory, and it seems like this is a close representation of that. The rectangles would be considered a node, and the lines connecting them would be considered an edge in graph theory.

    Read the article

  • How to determine collision direction between two rectangles?

    - by Jon
    I am trying to figure out how to determine the direction a collision occurs between two rectangles. One rectangle does not move. The other rectangle has a velocity in any direction. When a collision occurs, I want to be able to set the position of the moving rectangle to the point of impact. I seem to be stuck in determining from what direction the impact occurs. If I am moving strictly vertically or horizontally I manage great detection. But when moving in both directions at the same time, strange things happen. What is the best way to determine what direction a collision occurs between two rectangles?

    Read the article

  • Algorithm to reduce a bitmap mask to a list of rectangles?

    - by mos
    Before I go spend an afternoon writing this myself, I thought I'd ask if there was an implementation already available --even just as a reference. The first image is an example of a bitmap mask that I would like to turn into a list of rectangles. A bad algorithm would return every set pixel as a 1x1 rectangle. A good algorithm would look like the second image, where it returns the coordinates of the orange and red rectangles. The fact that the rectangles overlap don't matter, just that there are only two returned. To summarize, the ideal result would be these two rectangles (x, y, w, h): [ { 3, 1, 2, 6 }, { 1, 3, 6, 2 } ]

    Read the article

  • Rectangles Covering

    - by den bardadym
    I have N rectangles with sides parallel Ox and Oy. Exists another rectangele (model). I need create algorithm, which can tell: is model covered by N rectangles? and code him. I have some ideas. First I think need sort rectangles by left side (it can be done by O(n log n)). Then I think need use vertical sweeping line. Thanks.

    Read the article

  • Displaying rectangles in game window with XNA

    - by blerh
    I want to divide my game grid into an array of rectangles. Each rectangle is 40x40 and there are 14 rectangles in every column, with a total of 25 columns. This covers a game area of 560x1000. This is the code I have set up to make the first column of rectangles on the game grid: Rectangle[] gameTiles = new Rectangle[15]; for (int i = 0; i <= 15; i++) { gameTiles[i] = new Rectangle(0, i * 40, 40, 40); } I'm pretty sure this works, but of course I cannot confirm it because rectangles do not render on the screen for me to physically see them. What I would like to do for debugging purposes is to render a border, or fill the rectangle with color so I can see it on the game itself, just to make sure this works. Is there a way to make this happen? Or any relatively simple way I can just make sure that this works? Thank you very much.

    Read the article

  • Move 3 rectangles up in their X but keep order of rectangles

    - by Nicolas Martel
    I have 3 rectangles being rendered here. Let's say i wanted to move them all above the line yet keep their order, how would i go about that? I tried subtracting the Y and height rather than adding the Y it but as expected, the lower rectangle goes at the top, middle stays in the middle and top goes to the bottom before: after: So is there any simple solution to render them just above rather than having to change all values ?

    Read the article

  • Sort rectangles in a grid based on a comparison of the center point of each

    - by Mrwolfy
    If I have a grid of rectangles and I move one of the rectangles, say above and to the left of another rectangle, how would I resort the rectangles? Note the rectangles are in an array, so each rectangle has an index and a matching tag. All I really need to do is set the proper index based on the rectangles new center point position within the rectangle, as compared with the center point position of the other rectangles in the grid. Here is what I am doing now in pseudo code (works somewhat, but not accurate): -(void)sortViews:myView { int newIndex; // myView is the view that was moved. [viewsArray removeObject:myView]; [viewsArray enumerate:obj*view]{ if (myView.center.x > view.center.x) { if (myView.center.y > view.center.y) { newIndex = view.tag -1; *stop = YES; } else { newIndex = view.tag +1; *stop = YES; } } else if (myView.center.x < view.center.x) { if (myView.center.y > view.center.y) { newIndex = view.tag -1; *stop = YES; } else { newIndex = view.tag +1; *stop = YES; } } }]; if (newIndex < 0) { newIndex = 0; } else if (newIndex > 5) { newIndex = 5; } [viewsArray insertObject:myView atIndex:newIndex]; [self arrangeGrid]; }

    Read the article

  • Merging and splitting overlapping rectangles to produce non-overlapping ones

    - by uj
    I am looking for an algorithm as follows: Given a set of possibly overlapping rectangles (All of which are "not rotated", can be uniformly represented as (left,top,right,bottom) tuplets, etc...), it returns a minimal set of (non-rotated) non-overlapping rectangles, that occupy the same area. It seems simple enough at first glance, but prooves to be tricky (at least to be done efficiently). Are there some known methods for this/ideas/pointers? Methods for not necessarily minimal, but heuristicly small, sets, are interesting as well, so are methods that produce any valid output set at all.

    Read the article

  • Given a number of rectangles that can be rotated, find an enclosing rectangle of minimum area

    - by efficiencyIsBliss
    So, I'm trying to implement an algorithm that takes in a number of rectangles as input and tries to pack them into a rectangle of minimum area. The rectangles can all be rotated by 90 degrees. I realize that this is similar to the bin packing problem, but I am unable to find a good algorithm that accounts for the rotation. I found a paper that discusses this at length here and while I understand the article itself, I was hoping to find something simpler. Any suggestions? -Edit- I think I misstated the problem earlier. We are given a number of rectangles, such that each can be rotated by 90 degrees. We need to find a rectangle that fits all the given rectangles such that no two rectangles overlap, while minimizing the area of the enclosing rectangle. The problem I face here is that we are asked to find the minimum, as opposed to being given an enclosing rectangle and checking if the given rectangles fit or something of that sort.

    Read the article

  • Find the set of largest contiguous rectangles to cover multiple areas

    - by joelpt
    I'm working on a tool called Quickfort for the game Dwarf Fortress. Quickfort turns spreadsheets in csv/xls format into a series of commands for Dwarf Fortress to carry out in order to plot a "blueprint" within the game. I am currently trying to optimally solve an area-plotting problem for the 2.0 release of this tool. Consider the following "blueprint" which defines plotting commands for a 2-dimensional grid. Each cell in the grid should either be dug out ("d"), channeled ("c"), or left unplotted ("."). Any number of distinct plotting commands might be present in actual usage. . d . d c c d d d d c c . d d d . c d d d d d c . d . d d c To minimize the number of instructions that need to be sent to Dwarf Fortress, I would like to find the set of largest contiguous rectangles that can be formed to completely cover, or "plot", all of the plottable cells. To be valid, all of a given rectangle's cells must contain the same command. This is a faster approach than Quickfort 1.0 took: plotting every cell individually as a 1x1 rectangle. This video shows the performance difference between the two versions. For the above blueprint, the solution looks like this: . 9 . 0 3 2 8 1 1 1 3 2 . 1 1 1 . 2 7 1 1 1 4 2 . 6 . 5 4 2 Each same-numbered rectangle above denotes a contiguous rectangle. The largest rectangles take precedence over smaller rectangles that could also be formed in their areas. The order of the numbering/rectangles is unimportant. My current approach is iterative. In each iteration, I build a list of the largest rectangles that could be formed from each of the grid's plottable cells by extending in all 4 directions from the cell. After sorting the list largest first, I begin with the largest rectangle found, mark its underlying cells as "plotted", and record the rectangle in a list. Before plotting each rectangle, its underlying cells are checked to ensure they are not yet plotted (overlapping a previous plot). We then start again, finding the largest remaining rectangles that can be formed and plotting them until all cells have been plotted as part of some rectangle. I consider this approach slightly more optimized than a dumb brute-force search, but I am wasting a lot of cycles (re)calculating cells' largest rectangles and checking underlying cells' states. Currently, this rectangle-discovery routine takes the lion's share of the total runtime of the tool, especially for large blueprints. I have sacrificed some accuracy for the sake of speed by only considering rectangles from cells which appear to form a rectangle's corner (determined using some neighboring-cell heuristics which aren't always correct). As a result of this 'optimization', my current code doesn't actually generate the above solution correctly, but it's close enough. More broadly, I consider the goal of largest-rectangles-first to be a "good enough" approach for this application. However I observe that if the goal is instead to find the minimum set (fewest number) of rectangles to completely cover multiple areas, the solution would look like this instead: . 3 . 5 6 8 1 3 4 5 6 8 . 3 4 5 . 8 2 3 4 5 7 8 . 3 . 5 7 8 This second goal actually represents a more optimal solution to the problem, as fewer rectangles usually means fewer commands sent to Dwarf Fortress. However, this approach strikes me as closer to NP-Hard, based on my limited math knowledge. Watch the video if you'd like to better understand the overall strategy; I have not addressed other aspects of Quickfort's process, such as finding the shortest cursor-path that plots all rectangles. Possibly there is a solution to this problem that coherently combines these multiple strategies. Help of any form would be appreciated.

    Read the article

  • 2D Rectangle Collision Response with Multiple Rectangles

    - by Justin Skiles
    Similar to: Collision rectangle response I have a level made up of tiles where the edges of the level are made up of collidable rectangles. The player's collision box is represented by a rectangle as well. The player can move in 8 directions. The player's velocity is equal in X and Y directions and constant. Each update, I am checking the player's collision against all tiles that are a certain distance away. When the player collides with a rectangle, I am finding the intersection depth and resolving along the most shallow axis followed by the other axis. This resolution happens for both axes simultaneously. See below for two examples of situations where I am having trouble. Moving up-left against the left wall In the scenario below, the player is colliding with two tiles. The tile intersection depth is equal on both axes for the top tile and more shallow in the X axis for the middle tile. Because the player is moving up the wall, the player should slide in an upward direction along the wall. This works properly as long as the rectangle with the more shallow depth is evaluated first. If the equal intersection depth rectangle is evaluated first, there is a chance the player becomes stuck. Moving up-left against the top wall Here is an identical scenario with the exception that the collision is with the top wall. The same problem occurs at the corners when intersection depth is equal for both axes. I guess my overall question is: How can I ensure that collision response occurs on tiles that have non-equal intersection depth before tiles that have equal intersection depth in order to get around the weirdness that occurs at these corners. Sean's answer in the linked question was good, but his solution required having different velocity components in a certain direction. My situation has equal velocities, so there's no good way to tell which direction to resolve at corners. I hope I have made my explanation clear.

    Read the article

  • Eclipse on Ubuntu: Rectangles instead of Strings and some Java methods and classes

    - by Claus Hausberger
    after upgrading from Ubuntu 9.04. to 11.04 (new installation), I have weird problems with the Eclipse editor. With the Eclipse PyDev plugin, whenever I typ single quoted strings like 'bla', they appear as rectangles (both the quotes as well as the string). First I thought this was a problem with the PyDev plugin, but it also happens with Java and Scala Plugins. With Java, it happens, for example, when typing System.out.println("bla") and then "out" is shown as rectangles only. Weird is that for about half a second I see "System.out.println" and then the editor changes it to System.[][][].println (not really [] (here I used two brackets), it is shown as rectangles). This is very weird. I've never had this before with any Ubuntu, Java or Eclipse version. Currently, I use: Ubuntu 11.04. Eclipse 3.6 Java 1.6.0_25 The latest plugins for Python (2.1) and Scala (beta 5) where used. Eclipse and Ubuntu Terminal is set to UTF-8. The problem also happens when using KDE instead of Gnome. I doubt is has anything to do with Java as I use the same versions on older Ubuntu installations (10.04, 9.10, etc) at work. It does not happen with Netbeans. But I saw once error dialog message from the Update Manager where there were some rectangles in the error widget. Maybe this is the same problem Any ideas what could be wrong here and how to fix this? Eclipse is unusable but I need this for work and also for Scala and Python (the Eclipse plugins for those are very good now). Claus

    Read the article

  • What is an Efficient algorithm to find Area of Overlapping Rectangles

    - by namenlos
    My situation Input: a set of rectangles each rect is comprised of 4 doubles like this: (x0,y0,x1,y1) they are not "rotated" at any angle, all they are "normal" rectangles that go "up/down" and "left/right" with respect to the screen they are randomly placed - they may be touching at the edges, overlapping , or not have any contact I will have several hundred rectangles this is implemented in C# I need to find The area that is formed by their overlap - all the area in the canvas that more than one rectangle "covers" (for example with two rectangles, it would be the intersection) I don't need the geometry of the overlap - just the area (example: 4 sq inches) Overlaps shouldn't be counted multiple times - so for example imagine 3 rects that have the same size and position - they are right on top of each other - this area should be counted once (not three times) Example The image below contains thre rectangles: A,B,C A and B overlap (as indicated by dashes) B and C overlap (as indicated by dashes) What I am looking for is the area where the dashes are shown - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAA--------------BBB AAAAAAAAAAAAAAAA--------------BBB AAAAAAAAAAAAAAAA--------------BBB AAAAAAAAAAAAAAAA--------------BBB BBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBB-----------CCCCCCCC BBBBBB-----------CCCCCCCC BBBBBB-----------CCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC

    Read the article

  • Cutting out smaller rectangles from a larger rectangle

    - by Mauro Destro
    The world is initially a rectangle. The player can move on the world border and then "cut" the world via orthogonal paths (not oblique). When the player reaches the border again I have a list of path segments they just made. I'm trying to calculate and compare the two areas created by the path cut and select the smaller one to remove it from world. After the first iteration, the world is no longer a rectangle and player must move on border of this new shape. How can I do this? Is it possible to have a non rectangular path? How can I move the player character only on path? EDIT Here you see an example of what I'm trying to achieve: Initial screen layout. Character moves inside the world and than reaches the border again. Segment of the border present in the smaller area is deleted and last path becomes part of the world border. Character moves again inside the world. Segments of border present in the smaller area are deleted etc.

    Read the article

  • Tiling rectangles seamlessly in WPF

    - by Joe White
    I want to seamlessly tile a bunch of different-colored Rectangles in WPF. That is, I want to put a bunch of rectangles edge-to-edge, and not have gaps between them. If everything is aligned to pixels, this works fine. But I also want to support arbitrary zoom, and ideally, I don't want to use SnapsToDevicePixels (because it would compromise quality when the image is zoomed way out). But that means my Rectangles sometimes render with gaps. For example: <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="Black"> <Canvas SnapsToDevicePixels="False"> <Canvas.RenderTransform> <ScaleTransform ScaleX="0.5" ScaleY="0.5"/> </Canvas.RenderTransform> <Rectangle Canvas.Left="25" Width="100" Height="100" Fill="#CFC"/> <Rectangle Canvas.Left="125" Width="100" Height="100" Fill="#CCF"/> </Canvas> </Page> If the ScaleTransform's ScaleX is 1, then the Rectangles fit together seamlessly. When it's 0.5, there's a dark gray streak between them. I understand why -- the combined semi-transparent edge pixels don't combine to be 100% opaque. But I would like a way to fix it. I could always just make the Rectangles overlap, but I won't always know in advance what patterns they'll be in (this is for a game that will eventually support a map editor). Besides, this would cause artifacts around the overlap area when things were zoomed way in (unless I did bevel-cut angles on the underlapping portion, which is an awful lot of work, and still causes problems at corners). Is there some way I can combine these Rectangles into a single combined "shape" that does render without internal gaps? I've played around with GeometryDrawing, which does exactly that, but then I don't see a way to paint each RectangleGeometry with a different-colored brush. Are there any other ways to get shapes to tile seamlessly under an arbitrary transform, without resorting to SnapsToDevicePixels?

    Read the article

  • Spatial Index for Rectangles With Fast Insert

    - by TheCloudlessSky
    Hello, I'm looking for a data structure that provides indexing for Rectangles. I need the insert algorithm to be as fast as possible since the rectangles will be moving around the screen (think of dragging a rectangle with your mouse to a new position). I've looked into R-Trees, R+Trees, kD-Trees, Quad-Trees and B-Trees but from my understanding insert's are usually slow. I'd prefer to have inserts at sub-linear time complexity so maybe someone can prove me wrong about either of the listed data structures. I should be able to query the data structure for what rectangles are at point(x, y) or what rectangles intersect rectangle(x, y, width, height). EDIT: The reason I want insert so fast is because if you think of a rectangle being moved around the screen, they're going to have to be removed and then re-inserted. Thanks!

    Read the article

  • Fresh Vista install and the strange appearance of boxes/rectangles

    - by Nick
    I purchased a new hard-drive, and after doing a fresh install of Vista and installing all updates/latest drivers, I'm noticing that all of a sudden and shortly after being powered on, I get black boxes/rectangles all over my screen (below). Any ideas as to what could be causing this? On a (maybe) related note, my brand new hard-drive is squeaking. Not often, but it is there. Debating on whether or not it is worth the hassle of sending it back, or if this is related to the mysterious rectangles.

    Read the article

  • Issue with clipping rectangles and back to front rendering

    - by Milo
    Here is my problem. My rendering algorithm renders from back to front. But logically, clipping rectangles need to be applied from front to back. Hence why the following does not work: void AguiWidgetManager::recursiveRender(const AguiWidget *root) { //recursively calls itself to render widgets from back to front AguiWidget* nonConstRoot = (AguiWidget*)root; if(!nonConstRoot->isVisable()) { return; } //push the clipping rectangle if(nonConstRoot->isClippingChildren()) { graphicsContext->pushClippingRect(nonConstRoot->getClippingRectangle()); } if(nonConstRoot->isEnabled()) { nonConstRoot->paint(AguiPaintEventArgs(true,graphicsContext)); for(std::vector<AguiWidget*>::const_iterator it = root->getPrivateChildBeginIterator(); it != root->getPrivateChildEndIterator(); ++it) { recursiveRender(*it); } for(std::vector<AguiWidget*>::const_iterator it = root->getChildBeginIterator(); it != root->getChildEndIterator(); ++it) { recursiveRender(*it); } } else { nonConstRoot->paint(AguiPaintEventArgs(false,graphicsContext)); for(std::vector<AguiWidget*>::const_iterator it = root->getPrivateChildBeginIterator(); it != root->getPrivateChildEndIterator(); ++it) { recursiveRenderDisabled(*it); } for(std::vector<AguiWidget*>::const_iterator it = root->getChildBeginIterator(); it != root->getChildEndIterator(); ++it) { recursiveRenderDisabled(*it); } } //release clipping rectangle if(nonConstRoot->isClippingChildren()) { graphicsContext->popClippingRect(); } } I could ofcourse go to the top of the tree, then apply clipping rectangles inward until I get to the currently rendered widget, but that would involve lots of clipping rectangles @ 60 frames per second. I want to minimize calls to pushing and popping rectangles. What could I do, Thanks

    Read the article

  • interesting vba/access question: color rectangles according to data

    - by every_answer_gets_a_point
    i have a datasheet that looks like this: ID name_ 1 2 3 4 1 name1 x 0 0 0 2 name2 0 x 0 0 3 name3 0 0 x 0 4 name4 0 0 0 x i have rectangles on a report that correspond to this datasheet. when the report opens, i need the rectangles to be colored RED according to the data. for example where name1 and there is an x in the 1 column, i need the specific rectangle corresponding to this (name1, 1) to be colored red. here is the result that i will need: x x x x (where x is a rectangle that is RED) perhaps the best place to place this code would be in ON LOAD event of the report, but i am not sure exactly. can you please suggest to me some code that would turn the specified rectangles RED according to the data?

    Read the article

  • Algorithm to merge adjacent rectangles into polygon

    - by Glitch
    I guess that my problem is related to "convex hull", but no the same. All shapes in the drawing are rectangles with same width and height. Many are adjacent to each other. I want to combine those adjacent rectangles into polygons. Unlike "convex hull", the resuled polygons could be "hollow" inside. Is there any open source algorithm available?

    Read the article

  • Count max rectangles number, that can be placed inside character

    - by Nickolay
    Hi, I need a solution for quite complex problem. Exactly, I need to calculate the number of rectangles that can be placed inside letter/character with given size, considering that all rectangles are the same size, but it(the size) and the letter/character(of some regular specific font) itself can be changed by user(this will be used as webside calculator of signboard price). If describe this graphically, it looks like this. Any ideas or useful links will be much appreciated. Thanks in advance

    Read the article

  • Triangle - Rectangle Intersection in 2D

    - by Kevin Boyd
    I had previously asked this for 3D but now I changed my strategy and would like to do the intersection in 2D. The Rectangle is axis aligned and will always be in a fixed position, and has a constant shape and size, basically I want to clip the red areas of the triangles that extend outside the bounds of the rectangle The triangles could be in any position, shape or size, I my code I have a loop where I check the triangles one by one however I am still clueless about the math. I have identified 5 cases of triangle rectangle intersection as shown here. How do I find the intersection points of the triangle and the rectangle?

    Read the article

  • Ray-plane intersection to find the Z of the intersecting point

    - by Jenko
    I have a rectangle in 3d space (p1, p2, p3, p4) and when the mouse rolls over it I need to calculate the exact Z of the point on the rect, given the mouse coordinates (x, y). Would a Ray-plane intersection find the Z of the intersecting point? Edit: Would this one-liner work? .. it returns the t value for the intersection, apparently the Z value. float rayPlane(vector3D planepoint, vector3D normal, vector3D origin, vector3D direction){ return -((origin-planepoint).dot(normal))/(direction.dot(normal)); }

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >