📄 unitdesign.cpp
字号:
// UnitBase.cpp: implementation of the UnitBase class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "UnitDesign.h"
#include "math.h"
#include "compublic.h"
/*
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
*/
//////////////////////////////////////////////////
// 单元基类
//////////////////////////////////////////////////
UnitBase::UnitBase()
{
}
UnitBase::~UnitBase()
{
}
BOOL UnitBase::SetStartInf(double x, double y, double rAzimuth)
{
return FALSE;
}
BOOL UnitBase::GetEndInf(double &x, double &y, double &rAzimuth)
{
return TRUE;
}
BOOL UnitBase::Draw(BOOL bDraw)
{
return FALSE;
}
double UnitBase::ConvertFWJ(double a)
{
double rTep;
rTep = PI / 2 - a;
if (rTep < 0)
rTep += (2 * PI);
else if (rTep >= (2 * PI))
rTep -= (PI / 2);
return rTep;
}
double UnitBase::ConvertFWJ(ads_point pt1, ads_point pt2, ads_point pt3, ads_point pt4)
{
ads_point ptt;
int n = 0;
double rFwj, r1, r2;
r1 = ads_angle(pt1, pt2);
r2 = ads_angle(pt3, pt4);
rFwj = r2 - r1;
if (rFwj > PI)
{
rFwj = (2 * PI - r2) - r1;
}
if (rFwj <= -PI)
{
rFwj = r2 - (r1 - 2 * PI);
}
return (-1 * rFwj);
}
double UnitBase::ConvertPolar(double a)
{
double rTep;
rTep = PI / 2 - a;
return rTep;
}
BOOL UnitBase::GetXY(double l, double a, int n, double &x, double &y)
{
double rTepx, rTepy;
int i = 1, k = -1, m = 1;
x = l; y = pow(l, 3) / (6 * pow(a, 2));
while (i < n)
{
x += k * (pow(l, (m + 4)) / ((m + 4) * pow(2, i * 2) *
JieCheng(i * 2) * pow(a, m + 3)));
y += k * (pow(l, (m + 6)) / ((m + 6) * pow(2, (i * 2 + 1)) *
JieCheng(i * 2 + 1) * pow(a, m + 5)));
k *= (-1); m += 4; i++;
}
return TRUE;
}
double UnitBase::JieCheng(double a)
{
double i = 1;
double re = 1.0;
for (i = 1.0; i <= a; i += 1.0) re *= i;
return re;
}
BOOL UnitBase::GetLenInf(double len, double &x, double &y, double &rAzimuth)
{
return TRUE;
}
//////////////////////////////////////////////////
// 积木法线单元
//////////////////////////////////////////////////
LineUnit::LineUnit()
{
}
LineUnit::~LineUnit()
{
}
BOOL LineUnit::SetStartInf(double x, double y, double rAzimuth, double rlen)
{
m_rStartx = x;
m_rStarty = y;
m_rStartAzimuth = rAzimuth;
m_rLen = rlen;
m_rEndx = m_rStartx + m_rLen * sin(m_rStartAzimuth);
m_rEndy = m_rStarty + m_rLen * cos(m_rStartAzimuth);
m_rEndAzimuth = rAzimuth;
return TRUE;
}
BOOL LineUnit::GetEndInf(double &x, double &y, double &rAzimuth)
{
x = m_rEndx;
y = m_rEndy;
rAzimuth = m_rEndAzimuth;
return TRUE;
}
BOOL LineUnit::GetLenInf(double len, double &x, double &y, double &rAzimuth)
{
double xx, yy, a;
x = m_rStartx + len * sin(m_rStartAzimuth);
y = m_rStarty + len * cos(m_rStartAzimuth);
rAzimuth = m_rStartAzimuth;
return TRUE;
}
BOOL LineUnit::Draw(BOOL bDraw)
{
ads_point pt1, pt2;
struct resbuf *rbTmp = NULL;
Spoint(pt1, m_rStartx, m_rStarty, 0);
Spoint(pt2, m_rEndx, m_rEndy, 0);
MakeLine(pt1, pt2, 4, "0", rbTmp, bDraw);
ads_relrb(rbTmp);
return TRUE;
}
//////////////////////////////////////////////////
// 积木法圆曲线单元
//////////////////////////////////////////////////
CircleUnit::CircleUnit()
{
}
CircleUnit::~CircleUnit()
{
}
BOOL CircleUnit::SetStartInf(double x, double y, double rAzimuth, int iTurn, double len, double rR)
{
double aj, t, xm, ym;
m_rStartx = x;
m_rStarty = y;
m_rStartAzimuth = rAzimuth;
m_rStartPolar = ConvertPolar(rAzimuth);
m_iTurn = iTurn;
m_rLen = len;
m_rR = rR;
aj = m_rLen / m_rR;
t = m_rR * tan(aj / 2);
xm = m_rStartx + t * sin(m_rStartAzimuth);
ym = m_rStarty + t * cos(m_rStartAzimuth);
m_rEndAzimuth = m_rStartAzimuth + iTurn * aj;
m_rEndPolar = m_rStartPolar + iTurn * aj;
m_rEndx = xm + t * sin(m_rEndAzimuth);
m_rEndy = ym + t * cos(m_rEndAzimuth);
return TRUE;
}
BOOL CircleUnit::GetEndInf(double &x, double &y, double &rAzimuth)
{
x = m_rEndx;
y = m_rEndy;
rAzimuth = m_rEndAzimuth;
return TRUE;
}
BOOL CircleUnit::GetLenInf(double len, double &x, double &y, double &rAzimuth)
{
double rlen = 0.0;
rlen = m_rLen;
SetStartInf(m_rStartx, m_rStarty, m_rStartAzimuth, m_iTurn, len, m_rR);
x = m_rEndx;
y = m_rEndy;
rAzimuth = m_rEndAzimuth;
SetStartInf(m_rStartx, m_rStarty, m_rStartAzimuth, m_iTurn, rlen, m_rR);
return TRUE;
}
BOOL CircleUnit::Draw(BOOL bDraw)
{
double rTep, rStartAngle, rEndAngle;
ads_point ptcen, pt1, pt2, ptTep;
struct resbuf *rbTmp = NULL;
Spoint(pt1, m_rStartx, m_rStarty, 0.0);
ads_polar(pt1, m_rStartPolar, 0.01, pt2);
GetAngLine(pt1, pt2, 0, m_iTurn, PI / 2, m_rR, ptcen, ptTep);
rStartAngle = m_rStartPolar + m_iTurn * (PI / 2);
rEndAngle = rStartAngle - m_iTurn * (m_rLen / m_rR);
if (m_iTurn < 0)
{
rTep = rStartAngle;
rStartAngle = rEndAngle;
rEndAngle = rTep;
}
MakeArc(ptcen, m_rR,rEndAngle, rStartAngle, 2, "0", rbTmp, bDraw);
ads_relrb(rbTmp);
return TRUE;
}
//////////////////////////////////////////////////
// 积木法回旋线单元
//////////////////////////////////////////////////
AllayUnit::AllayUnit()
{
m_bFull = FALSE;
m_iBtoS = 1;
}
AllayUnit::~AllayUnit()
{
}
AllayUnit::SetStartInf(double x, double y, double rAzimuth,
int iTurn, double rA, double rstartR, double rendR)
{
double rTepR, r2;
m_iTurn = iTurn; m_rA = rA; m_rStartR = rstartR; m_rEndR = rendR;
m_rStartx = x; m_rStarty = y, m_rStartAzimuth = rAzimuth;
m_rEndx = 0.0; m_rEndy = 0.0; m_rEndAzimuth = 0.0;
m_bFull = FALSE;
m_iBtoS = 1;
//处理A值为零
if (rA == 0.0)
{
m_rLen = 0.0;
m_rEndx = m_rStartx; m_rEndy = m_rStarty; m_rEndAzimuth = m_rStartAzimuth;
return TRUE;
}
if(m_rStartR < m_rEndR)
{
//处理曲率由小到大
rTepR = m_rStartR;
m_iBtoS = FALSE;
}
else
{
rTepR = m_rEndR;
m_iBtoS = TRUE;
}
//处理完整回旋线
if (m_rStartR > 1000000 || m_rEndR > 1000000)
{
m_bFull = TRUE;
m_rLen = m_rA * m_rA / rTepR;
m_rEndx = INFINITY + 1;
GetFullAInfo(m_rStartx, m_rStarty, m_rStartAzimuth, m_iTurn,
m_rLen, m_rEndx, m_rEndy, m_rEndAzimuth);
}
//处理不完整回旋线
else
{
m_bFull = FALSE;
m_rLen = fabs(((m_rStartR - m_rEndR) * m_rA * m_rA) / (m_rStartR * m_rEndR));
m_rEndx = INFINITY + 1;
m_rTepLen = (m_rA * m_rA) / m_rStartR;
//m_rTepLen记录按完整回旋线计算至起点的曲线长
if (m_rStartR > m_rEndR)
{
r2 = m_rEndR; m_rEndR = 1E+20;
//如果大曲率到小曲率,则计算从开始到起点无穷大的参数,并记录于变量中
GetFullAInfo(m_rStartx, m_rStarty, m_rStartAzimuth + PI, m_iTurn * (-1),
m_rTepLen, m_rTepStartx, m_rTepStarty, m_rTepStartAzimuth);
m_rEndR = r2;
}
else
{
r2 = m_rEndR; m_rEndR = 1E+20;
//如果小曲率到大曲率,则计算从开始到起点无穷大的参数,并记录于变量中
GetFullAInfo(m_rStartx, m_rStarty, m_rStartAzimuth, m_iTurn,
m_rTepLen, m_rTepStartx, m_rTepStarty, m_rTepStartAzimuth);
m_rEndR = r2;
}
//获取终点信息
GetDeficAInfo(m_rStartx, m_rStarty, m_rStartAzimuth, m_iTurn,
m_rLen, m_rEndx, m_rEndy, m_rEndAzimuth);
}
return TRUE;
}
BOOL AllayUnit::GetEndInf(double &x, double &y, double &rAzimuth)
{
x = m_rEndx;
y = m_rEndy;
if (m_rEndAzimuth > 2 * PI)
rAzimuth = m_rEndAzimuth - 2 * PI;
else if (m_rEndAzimuth < 0.0)
rAzimuth = m_rEndAzimuth + (2 * PI);
else
rAzimuth = m_rEndAzimuth;
return TRUE;
}
BOOL AllayUnit::GetLenInf(double len, double &x, double &y, double &rAzimuth)
{
if (TRUE == m_bFull)
{
GetFullAInfo(m_rStartx, m_rStarty, m_rStartAzimuth,m_iTurn,
len, x, y, rAzimuth);
}
else
{
GetDeficAInfo(m_rStartx, m_rStarty, m_rStartAzimuth,m_iTurn,
len, x, y, rAzimuth);
}
return TRUE;
}
double AllayUnit::GetUnitLen()
{
double rLen;
rLen = m_rLen;
return rLen;
}
AllayUnit::GetFullAInfo(double rstartx, double rstarty, double rstartAzimuth, int iTurn,
double l, double &xx, double &yy, double &rcalAzimuth)
{
double rX, rY, t1, t2, aj, rTep, xm, ym, rEndR, xxx, yyy;
//如果计算曲率由小到大,并且是获取终点信息时调用
if (m_rEndR > m_rStartR && m_rEndx != INFINITY + 1)
{
l = (m_rLen - l + PARTICLE);
rstartx = m_rEndx;
rstarty = m_rEndy;
rstartAzimuth = m_rEndAzimuth + PI;
iTurn *= (-1);
}
//得出终点半径
rEndR = m_rA * m_rA / l;
//转角
aj = l / (2 * rEndR);
//由展开式计算X,Y值
GetXY(l, m_rA, 10, rX, rY);
//计算切线长
t1 = rX - rY / tan(aj); t2 = rY / sin(aj);
//如果不是获取终点信息,如果iBtoS调用
if (m_rEndR > m_rStartR && m_rEndx == INFINITY + 1)
{ rTep = t1; t1 = t2; t2 = rTep; }
//计算交点坐标
xm = rstartx + t1 * sin(rstartAzimuth);
ym = rstarty + t1 * cos(rstartAzimuth);
rcalAzimuth = rstartAzimuth + iTurn * aj;
xxx = xm + t2 * sin(rcalAzimuth);
yyy = ym + t2 * cos(rcalAzimuth);
//纠正假定方位角
if (m_rEndR > m_rStartR && m_rEndx != INFINITY + 1)
{
rcalAzimuth += PI;
}
xx = xxx; //返回计算坐标值
yy = yyy;
}
AllayUnit::GetDeficAInfo(double rstartx, double rstarty, double rstartAzimuth, int iTurn,
double l, double &xx, double &yy, double &rcalAzimuth)
{
ads_point pt;
struct resbuf *bnn = NULL;
double rTep, rTepR, a1, a2, a3, b1, b2, b3;
if (m_rStartR > m_rEndR)
{
GetFullAInfo(m_rTepStartx, m_rTepStarty, m_rTepStartAzimuth + PI,
m_iTurn, l + m_rTepLen, xx, yy, rcalAzimuth);
}
else
{
b1 = m_rEndx; b2 = m_rEndy; b3 = m_rEndAzimuth;
m_rEndx = m_rTepStartx; m_rEndy = m_rTepStarty; m_rEndAzimuth = m_rTepStartAzimuth;
m_iBtoS = FALSE; rTep = m_rLen; m_rLen = m_rTepLen;
rTepR = m_rEndR; m_rEndR = 1E+20;
GetFullAInfo(m_rStartx, m_rStarty, rstartAzimuth,
m_iTurn, l, a1, a2, a3);
m_rLen = rTep; m_rEndR = rTepR;
m_rEndx = b1; m_rEndy = b2; m_rEndAzimuth = b3;
xx = a1; yy = a2; rcalAzimuth = a3;
}
}
AllayUnit::Draw(BOOL bDraw)
{
int n, i, iColor = 1;
double rTepLong = 0.0, rTepx, rTepy, rfwj,rUnitLong = 0.0;
struct resbuf *rbTep = NULL;
AcGePoint3d ptTep;
AcGePoint3dArray ptTepArray;
if (m_rA == 0.0) return TRUE;
if (m_rStartR < m_rEndR) iColor = 6;
rUnitLong = m_rLen / 180;
n = 180;
if (FALSE == bDraw)
{
rUnitLong = 1.0;
double rTepLong;
ads_point pt1, pt2;
rTepLong = GetScreenH() / 30;
//生成起始及结束断面的短线
Spoint(pt1, m_rStartx, m_rStarty, 0.0);
ads_polar(pt1, ConvertPolar(m_rStartAzimuth + PI / 2.0),rTepLong / 2, pt1);
ads_polar(pt1, ConvertPolar(m_rStartAzimuth - PI / 2.0), rTepLong, pt2);
ads_grdraw(pt1, pt2, 256, 0);
Spoint(pt1, m_rEndx, m_rEndy, 0.0);
ads_polar(pt1, ConvertPolar(m_rEndAzimuth + PI / 2.0),rTepLong / 2, pt1);
ads_polar(pt1, ConvertPolar(m_rEndAzimuth - PI / 2.0), rTepLong, pt2);
ads_grdraw(pt1, pt2, 256, 0);
rUnitLong = m_rLen / 10;
n = 10;
iColor = 256;
}
ptTep.set(m_rStartx, m_rStarty, 0.00);
ptTepArray.append(ptTep);
if (TRUE == m_bFull)
{
for (i = 0; i < n; i++)
{
rTepLong += rUnitLong;
GetFullAInfo(m_rStartx, m_rStarty, m_rStartAzimuth,m_iTurn,
rTepLong, rTepx, rTepy, rfwj);
ptTep.set(rTepx, rTepy, 0.00);
ptTepArray.append(ptTep);
}
}
else
{
for (i = 0; i < n; i++)
{
rTepLong += rUnitLong;
GetDeficAInfo(m_rStartx, m_rStarty, m_rStartAzimuth,m_iTurn,
rTepLong, rTepx, rTepy, rfwj);
ptTep.set(rTepx, rTepy, 0.00);
ptTepArray.append(ptTep);
}
}
ptTep.set(m_rEndx, m_rEndy, 0.00);
ptTepArray.append(ptTep);
MakePline(ptTepArray, "0", 0.0, iColor, rbTep, bDraw);
ads_relrb(rbTep);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -