VC++(MFC)实现直角坐标系的输出
4个回答
2013-06-26
展开全部
void CTestDlg::OnButtonDraw()
{
DrawCoordinate(CPoint(100,250), 200, 6, 150, 10);
}
// 顶点坐标, x轴长度, x轴刻度数(含原点), y轴长度, y轴刻度数(含原点)
void CTestDlg::DrawCoordinate(CPoint point, int xLen, int xNum, int yLen, int yNum)
{
int x = xLen + 5;
int y = yLen + 5;
CDC *pDC = GetDC();
pDC->SetBkMode(TRANSPARENT); // 设置透明
pDC->MoveTo(point);
pDC->LineTo(CPoint(point.x+x, point.y)); // 绘制x轴
pDC->MoveTo(point);
pDC->LineTo(CPoint(point.x, point.y-y)); // 绘制y轴
pDC->TextOut(point.x-5, point.y+5, _T("0"));
pDC->TextOut(point.x+x+20, point.y-5, _T("X"));
pDC->TextOut(point.x-5, point.y-y-20, _T("Y"));
// 计算刻度宽度
int x_width = xLen / xNum;
int y_width = yLen / yNum;
int x_pixel = 0; // 当前x坐标
int y_pixel = 0; // 当前y坐标
for(int i=0; i<xNum; i++)
{
x_pixel = i*x_width;
pDC->MoveTo(CPoint(point.x+x_pixel, point.y-2)); // 绘制x轴刻度
pDC->LineTo(CPoint(point.x+x_pixel, point.y+4));
if(i > 0)
{
CString str;
str.Format(_T("%d"), i);
pDC->TextOut(point.x+x_pixel-2, point.y+3, str);
}
}
for(int j=0; j<yNum; j++)
{
y_pixel = j*y_width;
pDC->MoveTo(CPoint(point.x-2, point.y-y_pixel)); // 绘制y轴刻度
pDC->LineTo(CPoint(point.x+4, point.y-y_pixel));
if(j > 0)
{
CString str;
str.Format(_T("%d"), j);
pDC->TextOut(point.x-15, point.y-y_pixel-6, str);
}
}
ReleaseDC(pDC);
}
当然你也可以通过定义POINT数组,数组中记录每个点的坐标,接着使用CDC的PolyLineTo或PolyLine等多边形函数进行线段描绘,效果一样,看你喜欢哪种了
{
DrawCoordinate(CPoint(100,250), 200, 6, 150, 10);
}
// 顶点坐标, x轴长度, x轴刻度数(含原点), y轴长度, y轴刻度数(含原点)
void CTestDlg::DrawCoordinate(CPoint point, int xLen, int xNum, int yLen, int yNum)
{
int x = xLen + 5;
int y = yLen + 5;
CDC *pDC = GetDC();
pDC->SetBkMode(TRANSPARENT); // 设置透明
pDC->MoveTo(point);
pDC->LineTo(CPoint(point.x+x, point.y)); // 绘制x轴
pDC->MoveTo(point);
pDC->LineTo(CPoint(point.x, point.y-y)); // 绘制y轴
pDC->TextOut(point.x-5, point.y+5, _T("0"));
pDC->TextOut(point.x+x+20, point.y-5, _T("X"));
pDC->TextOut(point.x-5, point.y-y-20, _T("Y"));
// 计算刻度宽度
int x_width = xLen / xNum;
int y_width = yLen / yNum;
int x_pixel = 0; // 当前x坐标
int y_pixel = 0; // 当前y坐标
for(int i=0; i<xNum; i++)
{
x_pixel = i*x_width;
pDC->MoveTo(CPoint(point.x+x_pixel, point.y-2)); // 绘制x轴刻度
pDC->LineTo(CPoint(point.x+x_pixel, point.y+4));
if(i > 0)
{
CString str;
str.Format(_T("%d"), i);
pDC->TextOut(point.x+x_pixel-2, point.y+3, str);
}
}
for(int j=0; j<yNum; j++)
{
y_pixel = j*y_width;
pDC->MoveTo(CPoint(point.x-2, point.y-y_pixel)); // 绘制y轴刻度
pDC->LineTo(CPoint(point.x+4, point.y-y_pixel));
if(j > 0)
{
CString str;
str.Format(_T("%d"), j);
pDC->TextOut(point.x-15, point.y-y_pixel-6, str);
}
}
ReleaseDC(pDC);
}
当然你也可以通过定义POINT数组,数组中记录每个点的坐标,接着使用CDC的PolyLineTo或PolyLine等多边形函数进行线段描绘,效果一样,看你喜欢哪种了
东莞大凡
2024-08-07 广告
2024-08-07 广告
在东莞市大凡光学科技有限公司,我们利用Halcon软件处理机器视觉项目时,会用到自定义标定板以满足特定需求。Halcon支持用户根据实际应用场景自定义标定板形状与标记点。这不仅可以灵活应对不同工作环境,还能提高标定精度。通过调整圆点数量、间...
点击进入详情页
本回答由东莞大凡提供
展开全部
DrawCoordinate(CPoint(100,250), 200, 6, 150, 10);
}
// 顶点坐标, x轴长度, x轴刻度数(含原点), y轴长度, y轴刻度数(含原点)
void CTestDlg::DrawCoordinate(CPoint point, int xLen, int xNum, int yLen, int yNum)
{
int x = xLen + 5;
int y = yLen + 5;
CDC *pDC = GetDC();
pDC->SetBkMode(TRANSPARENT); // 设置透明
pDC->MoveTo(point);
pDC->LineTo(CPoint(point.x+x, point.y)); // 绘制x轴
pDC->MoveTo(point);
pDC->LineTo(CPoint(point.x, point.y-y)); // 绘制y轴
pDC->TextOut(point.x-5, point.y+5, _T("0"));
pDC->TextOut(point.x+x+20, point.y-5, _T("X"));
pDC->TextOut(point.x-5, point.y-y-20, _T("Y"));
// 计算刻度宽度
int x_width = xLen / xNum;
int y_width = yLen / yNum;
int x_pixel = 0; // 当前x坐标
int y_pixel = 0; // 当前y坐标
for(int i=0; i<xNum; i++)
{
x_pixel = i*x_width;
pDC->MoveTo(CPoint(point.x+x_pixel, point.y-2)); // 绘制x轴刻度
pDC->LineTo(CPoint(point.x+x_pixel, point.y+4));
if(i > 0)
{
CString str;
str.Format(_T("%d"), i);
pDC->TextOut(point.x+x_pixel-2, point.y+3, str);
}
}
for(int j=0; j<yNum; j++)
{
y_pixel = j*y_width;
pDC->MoveTo(CPoint(point.x-2, point.y-y_pixel)); // 绘制y轴刻度
pDC->LineTo(CPoint(point.x+4, point.y-y_pixel));
if(j > 0)
{
CString str;
str.Format(_T("%d"), j);
pDC->TextOut(point.x-15, point.y-y_pixel-6, str);
}
}
ReleaseDC(pDC);
}
}
// 顶点坐标, x轴长度, x轴刻度数(含原点), y轴长度, y轴刻度数(含原点)
void CTestDlg::DrawCoordinate(CPoint point, int xLen, int xNum, int yLen, int yNum)
{
int x = xLen + 5;
int y = yLen + 5;
CDC *pDC = GetDC();
pDC->SetBkMode(TRANSPARENT); // 设置透明
pDC->MoveTo(point);
pDC->LineTo(CPoint(point.x+x, point.y)); // 绘制x轴
pDC->MoveTo(point);
pDC->LineTo(CPoint(point.x, point.y-y)); // 绘制y轴
pDC->TextOut(point.x-5, point.y+5, _T("0"));
pDC->TextOut(point.x+x+20, point.y-5, _T("X"));
pDC->TextOut(point.x-5, point.y-y-20, _T("Y"));
// 计算刻度宽度
int x_width = xLen / xNum;
int y_width = yLen / yNum;
int x_pixel = 0; // 当前x坐标
int y_pixel = 0; // 当前y坐标
for(int i=0; i<xNum; i++)
{
x_pixel = i*x_width;
pDC->MoveTo(CPoint(point.x+x_pixel, point.y-2)); // 绘制x轴刻度
pDC->LineTo(CPoint(point.x+x_pixel, point.y+4));
if(i > 0)
{
CString str;
str.Format(_T("%d"), i);
pDC->TextOut(point.x+x_pixel-2, point.y+3, str);
}
}
for(int j=0; j<yNum; j++)
{
y_pixel = j*y_width;
pDC->MoveTo(CPoint(point.x-2, point.y-y_pixel)); // 绘制y轴刻度
pDC->LineTo(CPoint(point.x+4, point.y-y_pixel));
if(j > 0)
{
CString str;
str.Format(_T("%d"), j);
pDC->TextOut(point.x-15, point.y-y_pixel-6, str);
}
}
ReleaseDC(pDC);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-06-26
展开全部
用画线的方法,输出
比如一个箭头就画三条线
比如一个箭头就画三条线
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有一个setpitch的指令,你可以搜索一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询