回 帖 发 新 帖 刷新版面

主题:求教大家啦,刚开始玩BCB

void __fastcall TForm1::FormPaint(TObject *Sender)

{

double A,x1,y1,x2,y2;

int D=150,E=50;

double L,M,O,P;

for (int i=0; i<240; i++)

{

A = i*M_PI/120;

L = D+D/3*(1+cos(12*A)/2)*cos(A);

x1 = 240+1.25*L*cos(A);

M = E+E/3*(1+sin(12*A)/2)*cos(A);

x2 = 240+1.25*M*cos(A);

O = D+D/3*(1+cos(10*A)/2)*sin(A);

y1 = 240-O*sin(A);

P = E+E/2*(1+cos(15*A)/2)*sin(A);

y2 = 240-P*sin(A);

Canvas->MoveTo(x1,y1);

Canvas->LineTo(x2,y2);

}

}
为什么这个运行出现错误

回复列表 (共3个回复)

沙发


#include <vcl.h>
#pragma hdrstop
#include <math.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormPaint(TObject *Sender)
{
    double A,x1,y1,x2,y2;

int D=150,E=50;

double L,M,O,P;

for (int i=0; i<240; i++)

{

A = i*3.1415/120;

L = D+D/3*(1+cos(12*A)/2)*cos(A);

x1 = 240+1.25*L*cos(A);

M = E+E/3*(1+sin(12*A)/2)*cos(A);

x2 = 240+1.25*M*cos(A);

O = D+D/3*(1+cos(10*A)/2)*sin(A);

y1 = 240-O*sin(A);

P = E+E/2*(1+cos(15*A)/2)*sin(A);

y2 = 240-P*sin(A);

Canvas->MoveTo(x1,y1);

Canvas->LineTo(x2,y2);

}

}


添加了一个数学的头文件,还有,PI必须自己定义,或者去掉,用3.1415 代替

板凳

在Unit1.cpp最上面添加#include<math.h>
#define M_PI 3.1415926
变为下面的样子。
#include <vcl.h>
#pragma hdrstop
#include<math.h>
#include "Unit1.h"
#define M_PI 3.1415926

3 楼

这个问题我以前也接触过,开始的时候我也找不到问题的原因,后来我进了一个技术交流群,这个群里的人挺多的,在里面可以沟通技术,你可以进去看一下.群号是:六#二#八#七#八#零#四#三。另外,这个群里可以接项目。

我来回复

您尚未登录,请登录后再回复。点此登录或注册