MATLAB中:
圆
function circleplot(X,Y,R,HH,LL);
figure(‘menubar’,‘None’,‘toolbar’,‘None’);
colnum=round(2R/LL+1); %最中间的直径点数
x=linspace(-R,R,colnum); %最中间的直径横坐标 横线
Y=zeros(1,colnum);
plot(x,Y,‘r.’,‘MarkerSize’,5);
hold on;
for i =1:round(R/HH) %每次绘制一行
y=HHi;
hudu=acos(y/R); %反余弦 弧度
xaindist=Rsin(hudu); %弦长的一半
x=[ ];
x=linspace(-xaindist,xaindist,round(2xaindist/LL));
Y=yones(1,round(2xaindist/LL)); %每次绘制行的列值
plot(x,Y,‘r.’,‘MarkerSize’,5);
plot(x,-Y,‘r.’,‘MarkerSize’,5);
hold on
end
矩形
function rectangleplot(Length,Width,H,L);
figure(‘menubar’,‘None’,‘toolbar’,‘None’);
Nrow=round(Length/L+1); %列的点个数
Ncol=round(Length/H+1); %行的点个数
x=linspace(-Width/2,Width/2,Nrow);
y=linspace(-Length/2,Length/2,Ncol);
for i=1:Ncol %每次绘制一行
Y=ones(1,Nrow)*y(i); %每次绘制行的列值
plot(x,Y,‘r.’,‘MarkerSize’,5);
hold on;
end
mcc -W cpplib:librectangleplot -T link:lib rectangleplot.m
mcc -W cpplib:libcircleplot -T link:lib circleplot.m
VS中:
void CScanPatternSet::MovementPath(CString csTmp) {
if (csTmp == "0") {
//判断是否有画矩形的窗口
//if (libRectangleInitialize())
libcircleplotTerminate();
librectangleplotTerminate();
//}
//画圆
if (!libcircleplotInitialize())
{
printf("could not initialize !");
return;
}
//x y坐标 r半径 s采样间距
double _x[1] = { 0 };
double _y[1] = { 0 };
double _r[1] = { g_Parameter.dbDiameter / 2 };
double _hh[1] = { g_Parameter.dbLineSpacing };
double _ll[1] = { g_Parameter.dbSampLingInterval };
mwArray X(1, 1, mxDOUBLE_CLASS, mxREAL);
mwArray Y(1, 1, mxDOUBLE_CLASS, mxREAL);
mwArray R(1, 1, mxDOUBLE_CLASS, mxREAL);
mwArray HH(1, 1, mxDOUBLE_CLASS, mxREAL);
mwArray LL(1, 1, mxDOUBLE_CLASS, mxREAL);
X.SetData(_x, 1);
Y.SetData(_y, 1);
R.SetData(_r, 1);
HH.SetData(_hh, 1);
LL.SetData(_ll, 1);
circleplot(X, Y, R, HH, LL);
//::Sleep(1);
}
else if (csTmp == "1") {
//判断时候有画圆的窗口
//if (libCircularInitialize())
//{
libcircleplotTerminate();
librectangleplotTerminate();
//}
//画矩形
if (!librectangleplotInitialize())
{
printf("could not initialize !");
return;
}
if (g_Parameter.dbLength <= 0) {
MessageBox(_T("长度不能为0或者小于0的数字"));
g_Parameter.dbLength = 1;
}
if (g_Parameter.dbWidth <= 0) {
MessageBox(_T("宽度不能为0或者小于0的数字"));
g_Parameter.dbWidth = 1;
}
double _x[1] = { g_Parameter.dbLength };
double _y[1] = { g_Parameter.dbWidth };
double _h[1] = { g_Parameter.dbLineSpacing };
double _l[1] = { g_Parameter.dbSampLingInterval };
mwArray H(1, 1, mxDOUBLE_CLASS, mxREAL);
mwArray L(1, 1, mxDOUBLE_CLASS, mxREAL);
mwArray length(1, 1, mxDOUBLE_CLASS, mxREAL);
mwArray width(1, 1, mxDOUBLE_CLASS, mxREAL);
length.SetData(_x, 1);
width.SetData(_y, 1);
H.SetData(_h, 1);
L.SetData(_l, 1);
//调用matlab生成方法
rectangleplot(length, width, H, L);
//::Sleep(1);
}
//调用演示函数
HWND hFig = ::FindWindow(NULL, _T("Figure 1"));
//首先隐藏窗口
::ShowWindow(hFig, SW_HIDE);
//获得空间区域
CRect figure_rect;
CWnd *myfigure = GetDlgItem(IDC_STATIC_BG1);
myfigure->GetWindowRect(&figure_rect);
long fig_width = figure_rect.Width();
long fig_height = figure_rect.Height();
重置matlab figure窗口的父窗口
::SetParent(hFig, myfigure->GetSafeHwnd());
//去掉matlab figure窗口的标题栏和框架属性
long lStyle = ::GetWindowLong(hFig, GWL_STYLE);
::SetWindowLong(hFig, GWL_STYLE, lStyle&(~WS_CAPTION)&(~WS_THICKFRAME));
::ShowWindow(hFig, SW_SHOW);
//将matlab Figure窗口移动到空间位置
::SetWindowPos(hFig, NULL, 0, 0, fig_width, fig_height, SWP_NOZORDER | SWP_NOACTIVATE);
//????
//显示窗口
::ShowWindow(hFig, SW_SHOW);
//激活窗口
::SetForegroundWindow(this->m_hWnd);
Invalidate();
::UpdateWindow(hFig);
//::UpdateWindow(myfigure->m_hWnd); //刷新
}