I would like to be able to iterate through the grid elements with a set step size. The fun part of this problem is that the grid will be rotated. I have developed an algorithm to do this and it is successful for some cases. The image below specifies the problem:

The conditions of the problem are that a grid spacing will be provided that is a factor of the grid length and width (As a side note the grid can be rectangular). The Algorithm must iterate through the grid and print out where it is. Here is some code and an example of it working:
int main() {
vector< vector<double> > bound;
vector<double> point;
point.push_back(0);
point.push_back(4);
bound.push_back(point);
point[0] = 6; point[1] = 10;
bound.push_back(point);
point[0] = 4; point[1] = 0;
bound.push_back(point);
point[0] = 10; point[1] = 6;
bound.push_back(point);
double d = 0.5;
double x, y;
int countx = 0, county = 0;
for (double i = bound[0][0]; i < bound[2][0]; i+=d) {
//std::cout << "I: " << i << std::endl;
for (double j = bound[0][1]; j < bound[1][1]; j+=d) {
//std::cout << "J: " << j << std::endl;
x = i+d+(double)county*d;
y = j-(double)countx*d;
++county;
std::cout << "i, j, x and y: " << i << "\t" << j << "\t" << x << "\t" << y << std::endl;
}
std::cout << "new Row--------------------\n";
++countx;
county = 0;
}
}
The code above works and prints correctly the grid elements, ie:
x and y: 4, 0.5
x and y: 4.5, 1
etc.
However when trying a rectangle with bounds:
[(0.5, 6), (3, 8.5), (5.5, 1), (8, 3.5)]
and a step size (d) of 1
It iterates to outside the rectangle bounds. I can see why this is happening, the iterator condition in the for loop will not contain it because of the extra +d.
My question is, is there a better way to approach this problem and how would i go about it?
Does anyone know if this has been implemented before and has some source code?
Cheers for the help.
Ben
The Way I ended up going about it was to calculate the length and width of the rectangle by Pythagoras rule on two of the sides. I then made a grid on a virtual rectangle which is aligned with its bottom corner at the origin. Then by using a pre-developed library for matrix rotations and translations, I transformed the points individually by translating them to by the displacement to the bottom left corner and rotating them to the calculated angle of the rectangle.
This is similar to the above solution but uses a full transformation matrix. The answer ended up being simpler then I thought it would be.
Thanks for the help.