MirrorShape.cpp
资源名称:CAD.zip [点击查看]
上传用户:hehe2haha
上传日期:2013-08-16
资源大小:161k
文件大小:2k
源码类别:
CAD
开发平台:
Visual C++
- // MirrorShape.cpp: implementation of the MirrorShape class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "MirrorShape.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CMirrorShape::CMirrorShape()
- {
- SinAngle = 0;
- CosAngle = 0;
- TgAngle = 0;
- }
- CMirrorShape::~CMirrorShape()
- {
- }
- void CMirrorShape::SetSinCos(POINT BeginPos, POINT EndPos)
- {
- int Length = CDraw::Distance(BeginPos,EndPos);
- if (Length != 0)
- {
- //求参考线与X轴夹角的正弦、余弦
- SinAngle = (double)(EndPos.y - BeginPos.y) / Length;
- CosAngle = (double)(EndPos.x - BeginPos.x) / Length;
- //参考线与Y轴平行
- if (EndPos.x == BeginPos.x && EndPos.y != BeginPos.y);
- else
- {
- //求参考线与X轴夹角的正切
- TgAngle = (double)(EndPos.y - BeginPos.y) / (EndPos.x - BeginPos.x);
- }
- }
- }
- void CMirrorShape::SetMirrorPos(POINT BeginPos, POINT EndPos)
- {
- double Length = 0.0;
- double xOffset = 0.0;
- double yOffset = 0.0;
- MirrorBeginPos = SourceBeginPos;
- MirrorEndPos = SourceEndPos;
- //参考线与Y轴平行
- if (EndPos.x == BeginPos.x && EndPos.y != BeginPos.y)
- {
- xOffset = (double)2 * (BeginPos.x - SourceBeginPos.x);
- MirrorBeginPos.x += (long)xOffset;
- xOffset = (double)2 * (BeginPos.x - SourceEndPos.x);
- MirrorEndPos.x += (long)xOffset;
- }
- else
- {
- Length = BeginPos.y + TgAngle * (SourceBeginPos.x - BeginPos.x);
- Length = SourceBeginPos.y - Length;
- Length = Length * CosAngle;
- xOffset = 2 * Length * SinAngle;
- yOffset = 2 * Length * CosAngle;
- MirrorBeginPos.x += (long)xOffset;
- MirrorBeginPos.y -= (long)yOffset;
- Length = BeginPos.y + TgAngle * (SourceEndPos.x - BeginPos.x);
- Length = SourceEndPos.y - Length;
- Length = Length * CosAngle;
- xOffset = 2 * Length * SinAngle;
- yOffset = 2 * Length * CosAngle;
- MirrorEndPos.x += (long)xOffset;
- MirrorEndPos.y -= (long)yOffset;
- }
- }