What would be a good method to work out a list of points on a grid that fall within a square, given the center of the square and it's size.
Related
Rectangle frame is an area that needs to be split in 4 parts (not equal at all). I need sizing according to population in each area. Inside the rectangle I need to divide between two categories which can be part of any quadrants (split of rectangles). Circle could be oval or whole rectangle could be circular. But I need it easy and quick! This has been easy design on paper.
Thanks.
enter image description here
in the particle filter algorithm, particles should present as a dots or it can be represented as rectangle boxes? in the case of rectangle boxes, how I can determine the box size? if the object is far from the camera I want to show an object with a small box (particle), but when it is near the camera with a bog rectangle box (particle)
A particle is an element of the search space. If the search space is defined as the set of all possible positions (as in classical partical filters used for localization problems in mobile robotic) a particle is a position in this search space, aka a dot.
If you define the search space as set of all possible rectangles, a particle would represent a rectangle and therefore can be represented as one.
Thus, it sorely depends on the implementation of the particle filter.
Hi stackoverflow community,
This is a continuation of a question I asked 6 months regarding calculating the area and position of dynamically formed rectangles. The solution provided for that worked a treat but now I want to take this a step further.
Some background - I'm working on a puzzle game using Cocos2D/Box2D were the player draws lines on the screen. Depending on were the player draws, I want to then work out the area and position of polygons that appear as a result of the drawn lines.
In the following image, the black border represents a playing area, this will always be the same shape. The grey lines are player drawn and will always be straight. The green square is an obstacle. The obstacle objects will be convex shapes. The formed polygons (3 in this case) are the blue areas and are the shapes I'm trying to get the coordinates and area for.
I think I'll be fine with working out the area of a polygon using determinants but before that, I need to work out the coordinates of the blue polygons and I'm not sure how to do this.
I've got the lines (x,y) coordinates for both ends, the coordinates for the obstacle and the corner coordinates for the black border. Using those, is it possible to work out the coordinates of the blue polygons or am I approaching this the wrong way?
UPDATE - response to duffymo
Thanks for your answer. To explain further, each object mentioned is defined and encapsulated in a class i.e. I've got a Line/Obstacle/PlayingArea object. My polygon object is encapsulated in a 'Rectangle' object. Each one of these objects has it's own properties associated with it such as its coordinates/area/ID/state etc...
In order to keep track of all the objects, I've got an over-seeing singleton object which holds all of the Line objects / Obstacle objects etc in their own respective array. This way, I can loop through say all Lines and know were each one has been drawn by the player.
The game is a bit like classic JezzBall so I need to be able to create these polygon shapes when a user draws a line because the polygon shape will be used as my way of detecting if that particular area contains a ball. If not the area needs to be filled.
Since you already have the nodes and edges for your polygons, I'd recommend that you calculate the centroids, perimeters, and areas using contour integration You can express the centroids and areas as contour integrals using Green's theorem.
You can use Gaussian quadrature to do piecewise integration along each edge.
It'll be fast and accurate; it'll work on polygons of arbitrary complexity.
UPDATE: Objective-C is an object-oriented language. I don't know it myself, but I believe it's based on ideas from C and C++. Since that's the case, I'd recommend that you start writing more in terms of objects. Arrays of coordinates? They need to encapsulated together. I'd suggest a Point abstraction that encapsulates a point (id, x, y) together. Make a Grid that has a List of Points.
It sounds like users supply the relationship between Points to form Polygons. That's not clear from your description, so it's not a surprise that you're having trouble implementing it.
I'm trying to draw a triangle within a rectangle frame. I'm using two hand-gesture points startPoint and endPoint and calculating the thirdPoint (making the triangle equilateral). Drawing the triangle works fine the problem is that the frame that hold the rectangle size is base on the area of the hand-gesture so sometimes the third point gets cut off and does not show see bellow:
Is there any way I can add that third point so the frame so it takes it in consideration and does not get cut off.
Hello stackoverflow community,
I'm working on a puzzle game using Cocos2D/Box2D were the player draws lines on the screen. Depending on were the player draws, I want to then work out the area and position of the rectangles that appear as a result of the drawn lines.
I've currently got an array of all lines in the game so I know their (x, y) positions and sizes but I'm at a lost as to how to calculate the area and Cartesian coordinates of the rectangles that are dynamically formed. To help illustrate the problem, please see the following:
In the image above, you can see a black border. Contained within this are 4 grey lines which have been drawn by the player. From this, 5 blue rectangles have been formed. Any guidance or advice on how I can calculate the area and Cartesian coordinates of the rectangles would be a great help.
I wonder if it would be easier to convert the lines into a set of rectangles?
Start with a list of rectangles which only contains the main big rectangle. For each line, see which rectangle in the list contains it. Remove that rectangle from the list of rectangles and replace it with 2 smaller rectangles defined by the line.
Once you have the list of rectangles, you can easily calculate their area by just doing (width * height).