I assume that all eight lines will have the same distance, and all have one end at the endpoint. Further, that each line will be 45º from the two closest lines.
Let r = sqrt(32). Assume that I pass (r,0) and (-r,0) as the co-ordinates. Then the other coordinates should be (0,r), (0,-r), and all four possibilities of (±4,±4).
If that's the case, here's what to do.
1. Find the midpoint. The x- and y-coordinates are the averages of the two x- and y-coordinates, respectively. For the example of (r,0) and (-r,0), they average to (0,0).
- Xavg = (X1+X2)/2;
-
Yavg = (Y1+Y2)/2;
2. Consider a line from the midpoint to either point. Describe it in polar coordinates. Let (X,Y) be either (X1,Y1) or (X2,Y2).
- r = sqrt((X-Xavg)^2 + (Y-Yavg)^2);
-
theta = arctan((Y-Yavg)/(X-Xavg));
3. Rotate the line by multiples of 45 degrees, which is simple to do in polar coordinates. Do a loop that goes from 0 to 7, but not 8. Then calculate a temporary theta, and derive new coordinates. r stays the same.
- for(i = 0; i < 8; i++)
-
{
-
new_theta = theta + 45*(i);
-
new_X = r*cos(new_theta);
-
new_Y = r*sin(new_theta);
-
// Draw line from (Xavg,Yavg) to (new_X,new_Y)
-
}