Using OpenGL to draw the Maxwell rate distribution curve

Source: Internet
Author: User
Tags clear screen pow visual studio

This article supporting source code

Figure 1 Effect chart

Content feeds: formulas in "Expressions.h", the drawing program in "Draw.h", other parts of the OPENGGL program framework in OpenGL tutorial, see Resources.

Steps:

1. Create a new C + + Windows application with Microsoft Visual Studio. NET 2003, created in the project >> properties >> C + + >> precompiled Header ">>" Using precompiled headers, select Do not use Precompiled headers.

2. The header file containing the library required for OPENGGL is as follows:

#include <windows.h> // Header File For Windows
#include <gl\gl.h>  // Header File For The OpenGL32 Library
#include <gl\glu.h>  // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The GLaux Library

3. OPENGGL The required library connection mode (VS2003 screenshot below)

Figure 2 The connection diagram for the required libraries OPENGGL

At first I used debug to compile through, with release compiled there are many errors, research found that release and so on each configuration file to manually connect to the library.

4. Program Description

Header file: expressions.h
/*
Name: Maxwell Rate distribution function
Copyright:mozilla 1.1
Author: Zhang Shenpeng
Date:26-09-05 13:08
Description: If you have any questions, please contact zsp747@gmail.com,qq:375956667 (not used)
*/
#include <cmath>
using namespace Std;
Defining physical constants
const long double pi=3.1415926535897932384626433832795;
const float N_A=6.022E23;
const float P_0=1.013E5;
const double t_0=273.15;
const float v_0=22.4e-3;
const float R=P_0*V_0/T_0;
const float K=r/n_a;
Return in temperature (unit: K); Quality (unit: kg); Speed (unit m/s), the molecule
Template<class number>
Number percentage (number Temperature,number Quality,number speed)
{
quality=quality/n_a;
Return 4*pi*sqrt (Pow (quality/(2*pi*k*temperature), 3)) *
Pow (speed,2) *exp ((-quality*pow (speed,2))/(2*k*temperature));
}
Header file: draw.h
#include <gl\gl.h>//Header File for the OpenGL32 Library
#include <gl\glu.h>//Header File for the GLu32 Library
#include <gl\glaux.h>//Header File for the Glaux Library
Draw function curve
Template<class number>
void Drawexpression (number temperature,number quality)
{
Number x2=0,y2=0;//a point before
Glbegin (Gl_lines);
for (number speed=0;speed<2000;speed+=10)
{
Speed Unit Length 250m/s
Number x=speed/250;
Probability unit length 0.2%
Number Y=percentage (temperature,quality,speed) *500;
glcolor3f (0.0f,1.0f,0.0f);
glvertex3f (x,0, 0.0f); Solid curve
glvertex3f (X2,y2, 0.0f); Curve
glvertex3f (X,y, 0.0f); The connection between the previous point and the current point

Y2=y;x2=x;
}
Glend ();
}
Draw X,y Axis
void Drawxy ()
{

Glbegin (Gl_lines);
glvertex3f (0.0f, 0.0f, 0.0f);
glvertex3f (0.0f,5.0f, 0.0f);
glvertex3f (0.0f, 0.0f, 0.0f);
glvertex3f (7.0f,0.0f, 0.0f);
Glend ();
Arrow to draw an axis
Glbegin (Gl_triangles);
glvertex3f (6.0f,0.1f,0.0f);
glvertex3f (6.3f,0.0f,0.0f);
glvertex3f (6.0f,-0.1f,0.0f);
glvertex3f (0.1f,4.2f,0.0f);
glvertex3f (0.0f,4.5f,0.0f);
glvertex3f ( -0.1f,4.2f,0.0f);
Glend ();
}
int Drawglscene (glvoid)//here ' s Where We did all the Drawing
{
Glclear (Gl_color_buffer_bit |  Gl_depth_buffer_bit); Clear screen and Depth Buffer
Glloadidentity (); Reset the current Modelview Matrix

Gltranslatef ( -3.0f,-2.0f,-6.0f);
Drawxy ();

Drawexpression (70.0f,0.032f);
Drawexpression (273.0f,0.032f);
Drawexpression (300.0f,0.032f);
Drawexpression (373.0f,0.032f);
return TRUE; Everything Went OK
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.