Code: Show/Hide inline int round(double n)
{ return int((n >= 0.0) ? n + 0.5 : n - 0.5); } #define pi 3.1415926536 /* rotates points 45deg to make a diamond from a square */ inline void rotate(int half, int x, int y, int &rx, int &ry) { double r, theta; /* Make center origin */ x -= half; y = half - y; r = sqrt(x * x + y * y); theta = atan2(y, x); //sweet! theta += pi / 4; /* Convert back to upper-left origin */ rx = round(r * cos(theta)) + half; ry = round(r * sin(theta)) + half; } |
Code: Show/Hide void rotate(int px, int py, int xi, int yi, int &xo, int &yo, int angle)
{ /* convert to radians */ double ang = round((double)angle * 3.1415926535898 / 180.0); xo = px + round((double)(xi - px) * cos(ang) - (double)(yi - py) * sin(ang)); yo = py + round((double)(xi - px) * sin(ang) - (double)(yi - py) * cos(ang)); } |
Cyan~Fire wrote: |
Huh? I tried plugging that func in and all it did was draw a straight line, which makes sense since cos(pi/4) and sin(pi/4) are equal.
@Cerium: That "dotted line grid" is actually not a dotted line grid. The missing points are not evenly placed. |