|
-
September 11th, 2008, 08:30 PM
#1
Having the hardest time with line endcaps...
I figured that this has been dealt with so many time that there would be literally tons of resources all over the web. However, it would seems that it has been done so many times that they all dropped off of the edge of the web. I cannot find anything.
I'm in the VERY early design stages of making a PCB CAD program. I need lines of varying thickness and need precise control over them, so creating wide lines through geometric primitives is preferable to simply "thickening" pixels. I have a very good routine (posted below) that does just that and works very well. The problem is that I cannot figure out how to implement the end caps. I need the option of using either no end cap, square end caps or round end caps. Pretty standard. It *SEEMS* easy, but has proven very difficult. I guess I just cannot get my mind wrapped around the process.
I'd appreciate any help, whether math or code.
This is the code. It is still very early. As soon as I get the caps implemented, I'll switch it over to OpenGL for rendering.
Code:
void DrawLine(HDC hDC,Point start,Point end,double width)
{
Point left[2],right[2];
POINT sc_points[4];
double dx,dy,dx1,dy1,l,half_width;
half_width = width * .5;
if(width > 1)
{
dx = (end.x - start.x);
dy = (end.y - start.y);
l = sqrt(dx * dx + dy * dy);
if(l == 0)
return;
dx1 = (dx * half_width) / l;
dy1 = (dy * half_width) / l;
left[0].x = start.x - dy1;
left[0].y = start.y + dx1;
left[1].x = end.x - dy1;
left[1].y = end.y + dx1;
right[0].x = start.x + dy1;
right[0].y = start.y - dx1;
right[1].x = end.x + dy1;
right[1].y = end.y - dx1;
sc_points[0].x = left[0].x;
sc_points[0].y = left[0].y;
sc_points[1].x = left[1].x;
sc_points[1].y = left[1].y;
sc_points[2].x = right[1].x;
sc_points[2].y = right[1].y;
sc_points[3].x = right[0].x;
sc_points[3].y = right[0].y;
Polygon(hDC,sc_points,4);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|