Dividing a certain area into 1 km x 1 km square grids - gis

I have a map of a specific area (with about 1600 km width and 600 km height) and I will cover this entire area -which is not a straight shape like a rectangle or a square- with 1 km x 1 km square grids. I'm thinking of giving the starting latitude and longitude as the upper leftmost extreme point of my area -with that point being the upper left corner of the first square grid- and go from there. What would be the best way for me calculate the corners of all the square grids that will cover the my map? -I'm using C++ to calculate the corner variables for every square grid and then check if a given lat-lon pair falls within any one of these squares.- Thanks.

Related

<canvas> coordinate space vs. dimensions

Consider a 4x4 pixel HTML canvas element.
The coordinate system spans from (0,0) in the top left to (4,4) in the bottom right.
This represents a 5x5 grid.
It seems like the canvas squeezes one extra pixel in each dimension, without changing the width or height. How do I account for this if I want to draw precise pixels on an NxN canvas?
The coordinates (x,y) don't index pixels as if the canvas is a 2-d array.
In this case the region between grid lines does coincide with single pixels, but if we treat the canvas as a pixmap, then a pixel is the space between gridlines.
To draw pixel (i, j) with top-left corner at (x,y), do
canvas_context.fillRect(x, y, 1, 1);

Fill container with repeating squares

I love math, but I've been banging my head on this for a while.
I'm trying to fill a non square space with in HTML5 canvas with squares. I know the container width (W) and height (H). And I know the number of squares to use (n)
But the size of the square is what were trying to figure out. And how to draw it then. The squares should be just big enough to cover all the space, but it doesn't have to be sqrt(n) / sqrt(n). It should fill as much space as possible.
Any ideas on where to look to solve this?
Thanks!
A first estimate would be dividing the area W*H by the number of squares n. That will give you the area for each square, and taking the square root of that area will give you its length.
But that only works in cases where the rectangle can be exactly filled by these squares. If you might need some overlap beyond the rectangle, then you might have to adjust either the lengths or the number of squares. So suppose you want to cover your rectangle (i.e. fill a slightly larger rectangle) with no more than n squares, choosing the squares as small as possible under these circumstances. Do the above computation. Suppose that tells you that you'll need 3.75 rows and 6.23 columns of squares. Then you know that more rows or columns will require more than n squares. So you'll have to assume 3 rows and 6 columns. You can compute square lengths of H/3 and W/6 and take the larger of these.
Your scenario often is unsolvable.
For example, consider a 2 x 3 area. You can't fit either 5 or 7 squares into this area.

How to draw a triangle by two(or three) given angles with angles written at each corners in actionscript ?

I tried to google it but couldn't find a solution.there are method to draw a triangle with one given angle and two lengths .but i want to draw triangle with given two angles.Can some one guild me..
A triangle is defined correctly only by 2 sides and angle between them, 3 sides, or 1 side and both angles containing that side. Using three angles you can only define a set of triangles. The first commenter said draw a pixel, and he's mathematically correct, as a triangle with infintely small sides, but with 3 correct angles, will be displayed as a single dot. So, you need to define at least one side before you can get a correct displayed triangle.

an area of the earth that is to be partitioned into 100 km by 100 km square areas

Let's say I have a large geographic area SW (South-West) Latitude, Longitude and NE (North-East) Lat, Long and I want multiple areas of 100KM by 100KM squares to be divided.
So that if large part has 1000KM by 1000KM then I need ten of 100KM by 100KM squares area to be partitioned with their SW LAT-LONG and NE LAT-LONG.
Any sample formula that does the partition?
Well first of all, since they're on tne surface of a sphere they will not be exact squares, but curved surfaces with parallel top and bottom boundaries and non-parallel side boundaries. and since the latitude of the northern-most row of "squares" will be different than the latitude of the southernmost row, you have to decide how important is it that the sides (vertical boundaries) be exactly 100 km...
(Side note: it is impossible -very very difficult -- to guarantee that the top and bottom horizontal boundaries will be exactly 100 km, unless the "square" exactly straddles the equator)
If it is critical, then the vertical boundaries between "squares in each row will not line up with the vertical boundary lines of the row above and below it... On the other hand if the length of the sides is not critical, i.e., if only the area of each "square" needs to be the same, then you can make the vertical lines (side boundaries) coincident between rows and just make each successive row of "squares a bit taller or short (north-to-sount) to keep the area of the squares in each row the same...

Smallest possible bounding box for a rotated image

Suppose I have some arbitrary input image with width w1 and height h1. I want to rotate this image all the way around 360 degrees back to the starting position. However, if the image is of anything except a circle, then the edges of the image will be clipped if the canvas it is drawn onto remains at size w1 by h1.
What I need then is to determine the canvas size (width w2 and height h2) that can be used for all rotated versions of the input image. I know that w2 == h2, and thus the desired canvas size is a square, because it is obvious that we are rotating something about a center point, and the final image (after 360 rotations) is essentially a circle.
The other thing to consider is that objects such as squares will have corners that will stick out, so just using the max value of width or height for both dimensions also does not work.
One solution I have come up with is to create the canvas larger than I need (for example by setting w2 and h2 to max(w1, h1) * 2, rotating everything, and then trimming all the transparent pixels. This is not very efficient and I would much rather be able to calculate the tightest bounding box upfront.
This is a geometry question. You essentially want to find the diameter (d) of a circle that would inscribe your original canvas and then w2 = h2 = d
The diameter of such a circle would be √(w1^2+h1^2)
So w2 = h2 = √(w1^2+h1^2)
Also, to avoid clipping, you might want to take the ceiling of that result rather than rounding.
If the image being rotated in a square, you'd have to make the canvas height and width the same length as the hypotenuse.
w = h = sqrt(h^2 + w^2)
(I do not know actionscript)
However, if the image you have is not in a square, you'll essentially have to find the point farthest away from the center...
PS: It's late and I'm rambling, so I'm sorry if this might be wrong.
Your canvas need to be a square.
If you are going to rotate a body like the green figure around any point (in this example Point A), the side of the square is the double of the distance to the most distant point to A in the body.