程序之美
前言
模拟气体分子的运动,能直观地检测那些热力学公式的正确性。本程序设计成所有粒子之间的力都是斥力,粒子和边界之间也有斥力。粒子在二维平面运动。
主体
运行效果
代码示例
#include <graphics.h> // 引用图形库头文件
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define Round(d) int(floor(d + 0.5)) // 四舍五入宏定义
#define Xsize 960
#define Ysize 960
class Vector2D // 定义二维向量类
{
public:
Vector2D() {};
Vector2D(double a, double b)
{
x = a;
y = b;
length = sqrt(x * x + y * y);
};
void vectorAB(double ax, double ay, double bx, double by) // 生成 A B 向量
{
x = bx - ax;
y = by - ay;
length = sqrt(x * x + y * y);
};
void minusVector(Vector2D v) // 变成负向量
{
x = -v.x;
y = -v.y;
le