两跨连续梁影响线绘制(一)

题目大意:

  如图所示,用户输入跨度L1和L2,绘制出B点的影响线。

 效果:

步骤:

一、计算影响线

 二、添加计算类:CCalculation

CCalculation.h

#pragma once
//计算影响线的公式
class CCalculation
{
public:
	CCalculation(void);
	CCalculation(const double l1,const double l2);
	CCalculation(const double l1,const double l2,const double l3);
	virtual ~CCalculation(void);
public:
    void Initlize(void);
	double GetInfluenceY(const double x) const;
	double GetEffectCoeffient() const;
	double GetSpanL1() const;
	double GetSpanL2() const;
	double GetSpanL3() const;
	double GetLength() const;
private:
	double m_dL1;
	double m_dL2;
	double m_dL3;

};

CCalculation.cpp

#include "stdafx.h"
#include "CCalculation.h"
#include <math.h>

CCalculation::CCalculation(void)
{
}


CCalculation::CCalculation(const double l1,const double l2)
	:m_dL1(l1),m_dL2(l2)
{

}

CCalculation::CCalculation(const double l1,const double l2,const double l3)
	:m_dL1(l1),m_dL2(l2),m_dL3(l3)
{

}

CCalculation::~CCalculation(void)
{
}


void CCalculation::Initlize(void)
{
	m_dL1 = 50;
	m_dL2 = 50;
	m_dL3 = 15;
}

double CCalculation::GetInfluenceY(const double x) const
{
	double dL1=GetSpanL1();
	double dL2=GetSpanL2();
	double dL=GetLength();
	assert(x>=0);
	if (x>=0 && x<=dL1)
	{
		return x*(dL1-x)*(dL1+x)/(dL1*(dL1+dL2));
	}
	else
	{
		return (x-dL1)*(dL2-(x-dL1))*(2*dL2-(x-dL1))/(dL2*(dL1+dL2));
	}
}

double CCalculation::GetEffectCoeffient() const
{
	return m_dL1+m_dL2+m_dL3;
}

double CCalculation::GetSpanL1() const
{
	return m_dL1;
}

double CCalculation::GetSpanL2() const
{
	return m_dL2;
}

double CCalculation::GetSpanL3() const
{
	return m_dL3;
}

double CCalculation::GetLength() const
{
	return m_dL1+m_dL2;
}

三、添加绘制影响线的类:CDrawLine

CDrawLine.h

#pragma once
#include <afxwin.h>
class CDrawLine:public CWnd
{
public:
	CDrawLine(void);
	virtual ~CDrawLine(void);
public:
	void DrawInfulenceLine(CWnd *pWnd,double dLength1,double dLength2) const;

};

CDrawLine.cpp

#include "stdafx.h"
#include "CDrawLine.h"

#include "resource.h"
#include "CCalculation.h"
#include "InfluenceLineDlg.h"

CDrawLine::CDrawLine(void)
{

}

CDrawLine::~CDrawLine(void)
{
}

void CDrawLine::DrawInfulenceLine(CWnd *pWnd,double dLength1,double dLength2) const
{
	CRect rect;
	pWnd->GetClientRect(&rect);
	CDC *pDC = pWnd->GetDC();
	pWnd->Invalidate();
	pWnd->UpdateWindow();

	CPen newPen;       
	CPen *pOldPen;    

	CBrush newBrush;   
	CBrush *pOldBrush; 

	newBrush.CreateSolidBrush(RGB(255,255,255));   
	pOldBrush = pDC->SelectObject(&newBrush);   
	pDC->Rectangle(rect);   
	pDC->SelectObject(pOldBrush);   
	newBrush.DeleteObject();   

	newPen.CreatePen(PS_SOLID, 2, RGB(0,0,0));   
	pOldPen = pDC->SelectObject(&newPen);   

	CCalculation Cal(dLength1,dLength2);
	double dL = Cal.GetLength();
	double dL1 = Cal.GetSpanL1();
	double dL2 = Cal.GetSpanL2();

	int nWidth = rect.Width();
	int nHeight = rect.Height();

	pDC->MoveTo(nWidth/10,nHeight/2);
	pDC->LineTo(9*nWidth/10,nHeight/2);

	CPoint Pt1[4];
	Pt1[0] = CPoint(nWidth/10, nHeight/2);
	Pt1[1] = CPoint(nWidth/10-12, nHeight/2+20);
	Pt1[2] = CPoint(nWidth/10+12,  nHeight/2+20);
	Pt1[3] = CPoint(nWidth/10, nHeight/2);
	pDC->Polyline(Pt1, 4);

	CPoint Pt2[4];
	Pt2[0] = CPoint(nWidth/10+(int)(dL1*(8*nWidth/10)/dL), nHeight/2);
	Pt2[1] = CPoint(int(nWidth/10+dL1*(8*nWidth/10)/dL-12), nHeight/2+20);
	Pt2[2] = CPoint(int(nWidth/10+dL1*(8*nWidth/10)/dL+12),  nHeight/2+20);
	Pt2[3] = CPoint(nWidth/10+(int)(dL1*(8*nWidth/10)/dL), nHeight/2);
	pDC->Polyline(Pt2, 4);

	CPoint Pt3[4];
	Pt3[0] = CPoint(9*nWidth/10, nHeight/2);
	Pt3[1] = CPoint(9*nWidth/10-12, nHeight/2+20);
	Pt3[2] = CPoint(9*nWidth/10+12,  nHeight/2+20);
	Pt3[3] = CPoint(9*nWidth/10, nHeight/2);
	pDC->Polyline(Pt3, 4);

	pDC->TextOut(nWidth/10,nHeight/2+25,_T("A"));
	pDC->TextOut(nWidth/10+(int)(dL1*(8*nWidth/10)/dL),nHeight/2+25,_T("B"));
	pDC->TextOut(9*nWidth/10,nHeight/2+25,_T("C"));

	pDC->TextOut(nWidth/10+(int)(dL1/2*(8*nWidth/10)/dL),nHeight/2-25,_T("L1"));
	pDC->TextOut(nWidth/10+((int)dL1+(int)dL2/2)*(8*nWidth/10)/(int)dL,nHeight/2-25,_T("L2"));

	//绘制影响线
	int nX=0;
	int nY=0;
	pDC->MoveTo(nWidth/10,nHeight/2);
	for (int i = 0;i <=(int)dL; i++)
	{
		nX=nWidth/10+(i*8*nWidth/10)/(int)dL;
		nY=nHeight/2 + (int)(Cal.GetInfluenceY(i))*2;	
		pDC->LineTo(nX,nY);

	}
	//输出最大弯矩影响系数
	int nMaxY1=(int)(Cal.GetInfluenceY(dLength1/2));	
	int nMaxY2=(int)(Cal.GetInfluenceY(dLength1+dLength2/2));
	CString strY1=_T("");
	CString strY2=_T("");
	strY1.Format(_T("%d"),nMaxY1);
	strY2.Format(_T("%d"),nMaxY2);
	pDC->TextOut(nWidth/10+(int)(dL1/2*(8*nWidth/10)/dL),nHeight/2 +nMaxY1*2+7,strY1);
	pDC->TextOut(nWidth/10+(int)(dL1+dL2/2)*(8*nWidth/10)/(int)dL-10,nHeight/2 +nMaxY2*2+7,strY2);

	pDC->SelectObject(pOldPen);   
	newPen.DeleteObject();  
}

四、对话框类:InfluenceLineDlg

InfluenceLineDlg.h


// InfluenceLineDlg.h : 头文件
//

#pragma once
#include "afxwin.h"


// CInfluenceLineDlg 对话框
class CInfluenceLineDlg : public CDialogEx
{
// 构造
public:
	CInfluenceLineDlg(CWnd* pParent = NULL);	// 标准构造函数

// 对话框数据
	enum { IDD = IDD_INFLUENCELINE_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV 支持


// 实现
protected:
	HICON m_hIcon;

	// 生成的消息映射函数
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnBnClickedButtonInfluenceline();
	double m_dLength1;
	double m_dLength2;
	CStatic m_picDraw;
	
	double m_dLength3;
	double m_dEffCoeff;
	afx_msg void OnBnClickedButtonEffectCoeffient();
};

InfluenceLineDlg.cpp


// InfluenceLineDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "InfluenceLine.h"
#include "InfluenceLineDlg.h"
#include "afxdialogex.h"
#include "CCalculation.h"
#include "CDrawLine.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialogEx
{
public:
	CAboutDlg();

// 对话框数据
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CInfluenceLineDlg 对话框



CInfluenceLineDlg::CInfluenceLineDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CInfluenceLineDlg::IDD, pParent)
	, m_dLength3(0)
	, m_dEffCoeff(0)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	CCalculation calInit;
	calInit.Initlize();

	m_dLength1 = calInit.GetSpanL1();
	m_dLength2 = calInit.GetSpanL2();
	m_dLength3 = calInit.GetSpanL3();
	m_dEffCoeff = calInit.GetEffectCoeffient();
}

void CInfluenceLineDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m_dLength1);
	DDX_Text(pDX, IDC_EDIT2, m_dLength2);
	DDX_Control(pDX, IDC_INFLUENCELINE_DRAW, m_picDraw);
	DDX_Text(pDX, IDC_EDIT4, m_dLength3);
	DDX_Text(pDX, IDC_EDIT_COEFFICIENT, m_dEffCoeff);
}

BEGIN_MESSAGE_MAP(CInfluenceLineDlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_INFLUENCELINE, &CInfluenceLineDlg::OnBnClickedButtonInfluenceline)
	ON_BN_CLICKED(IDC_BUTTON_EFFECT_COEFFIENT, &CInfluenceLineDlg::OnBnClickedButtonEffectCoeffient)
END_MESSAGE_MAP()


// CInfluenceLineDlg 消息处理程序

BOOL CInfluenceLineDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();


	// 将“关于...”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码


	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}

void CInfluenceLineDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialogEx::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。

void CInfluenceLineDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);

	}
	else
	{
		CDialogEx::OnPaint();
		//初始化影响线
		CWnd *pWnd = GetDlgItem(IDC_INFLUENCELINE_DRAW);

		CDrawLine Draw;
		Draw.DrawInfulenceLine(pWnd,m_dLength1,m_dLength2);
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CInfluenceLineDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}



void CInfluenceLineDlg::OnBnClickedButtonInfluenceline()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);

	if (m_dLength1<30 || m_dLength1>160 || m_dLength2<30 || m_dLength2>160)
	{
		 AfxMessageBox(_T("连续梁适用跨度为30~160m!"));
		 return;
	}
	//绘制影响线
	CWnd *pWnd = GetDlgItem(IDC_INFLUENCELINE_DRAW);

	CDrawLine Draw;
	Draw.DrawInfulenceLine(pWnd,m_dLength1,m_dLength2);
}




void CInfluenceLineDlg::OnBnClickedButtonEffectCoeffient()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	CCalculation calEfCo(m_dLength1,m_dLength2,m_dLength3);
	m_dEffCoeff = calEfCo.GetEffectCoeffient();
	UpdateData(FALSE); 
}

项目完整代码:

链接:https://pan.baidu.com/s/1Gc7eSYktCzVOZrSaqGb9Ew 
提取码:sa5x

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值