Здравствуйте хотел спросить на тему ,как построить график в windows form , на си++ я делаю проект по физике на тему поляризация , нужно построить график так чтобы отображалась сначала линейная поляризация, круговая и эллиптическая . Формулы для построения , так же я вывел формулу для Еу (чтобы подставлять точки Ех) спасибо если дочитали до конца ,если можете помочь буду рад услышать предложения.
#pragma once
#include"cmath"
namespace polarization {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Сводка для MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart1;
protected:
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::RadioButton^ radioButton1;
private: System::Windows::Forms::RadioButton^ radioButton2;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::RadioButton^ radioButton3;
private: System::Windows::Forms::RadioButton^ radioButton4;
private: System::Windows::Forms::RadioButton^ radioButton5;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ информацияToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ оПрограммеToolStripMenuItem;
private:
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
void InitializeComponent(void)
{
System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea1 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
System::Windows::Forms::DataVisualization::Charting::Series^ series1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm::typeid));
this->chart1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton2 = (gcnew System::Windows::Forms::RadioButton());
this->button1 = (gcnew System::Windows::Forms::Button());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->radioButton3 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton4 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton5 = (gcnew System::Windows::Forms::RadioButton());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->информацияToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->оПрограммеToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart1))->BeginInit();
this->menuStrip1->SuspendLayout();
this->SuspendLayout();
//
// chart1
//
this->chart1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)
| System::Windows::Forms::AnchorStyles::Left)
| System::Windows::Forms::AnchorStyles::Right));
chartArea1->Name = L"ChartArea1";
this->chart1->ChartAreas->Add(chartArea1);
this->chart1->Location = System::Drawing::Point(96, 26);
this->chart1->Margin = System::Windows::Forms::Padding(2);
this->chart1->Name = L"chart1";
series1->ChartArea = L"ChartArea1";
series1->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Line;
series1->Name = L"1";
this->chart1->Series->Add(series1);
this->chart1->Size = System::Drawing::Size(200, 385);
this->chart1->TabIndex = 0;
this->chart1->Text = L"График";
//
// textBox1
//
this->textBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->textBox1->Location = System::Drawing::Point(354, 69);
this->textBox1->Margin = System::Windows::Forms::Padding(2);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(94, 20);
this->textBox1->TabIndex = 2;
//
// textBox2
//
this->textBox2->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->textBox2->Location = System::Drawing::Point(484, 69);
this->textBox2->Margin = System::Windows::Forms::Padding(2);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(99, 20);
this->textBox2->TabIndex = 3;
//
// radioButton1
//
this->radioButton1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->radioButton1->AutoSize = true;
this->radioButton1->Location = System::Drawing::Point(539, 135);
this->radioButton1->Margin = System::Windows::Forms::Padding(2);
this->radioButton1->Name = L"radioButton1";
this->radioButton1->Size = System::Drawing::Size(33, 17);
this->radioButton1->TabIndex = 4;
this->radioButton1->TabStop = true;
this->radioButton1->Text = L"pi";
this->radioButton1->UseVisualStyleBackColor = true;
this->radioButton1->CheckedChanged += gcnew System::EventHandler(this, &MyForm::radioButton1_CheckedChanged);
//
// radioButton2
//
this->radioButton2->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->radioButton2->AutoSize = true;
this->radioButton2->Location = System::Drawing::Point(435, 135);
this->radioButton2->Margin = System::Windows::Forms::Padding(2);
this->radioButton2->Name = L"radioButton2";
this->radioButton2->Size = System::Drawing::Size(44, 17);
this->radioButton2->TabIndex = 5;
this->radioButton2->TabStop = true;
this->radioButton2->Text = L"pi/2";
this->radioButton2->UseVisualStyleBackColor = true;
//
// button1
//
this->button1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->button1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button1.BackgroundImage")));
this->button1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::None;
this->button1->ForeColor = System::Drawing::SystemColors::ButtonHighlight;
this->button1->Location = System::Drawing::Point(360, 175);
this->button1->Margin = System::Windows::Forms::Padding(2);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(223, 44);
this->button1->TabIndex = 6;
this->button1->Text = L"Построить ";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// label1
//
this->label1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->label1->AutoSize = true;
this->label1->ForeColor = System::Drawing::SystemColors::ActiveCaptionText;
this->label1->Location = System::Drawing::Point(416, 108);
this->label1->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(81, 13);
this->label1->TabIndex = 7;
this->label1->Text = L"Разность фаз ";
//
// label2
//
this->label2->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->label2->AutoSize = true;
this->label2->BackColor = System::Drawing::SystemColors::ActiveCaption;
this->label2->Font = (gcnew System::Drawing::Font(L"Arial Rounded MT Bold", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label2->ForeColor = System::Drawing::SystemColors::ControlText;
this->label2->Location = System::Drawing::Point(346, 31);
this->label2->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(126, 18);
this->label2->TabIndex = 8;
this->label2->Text = L"Амплитуда по икс";
//
// label3
//
this->label3->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->label3->AutoSize = true;
this->label3->Font = (gcnew System::Drawing::Font(L"Arial Rounded MT Bold", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label3->ForeColor = System::Drawing::SystemColors::ActiveCaptionText;
this->label3->Location = System::Drawing::Point(470, 31);
this->label3->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(140, 18);
this->label3->TabIndex = 9;
this->label3->Text = L"Амплитуда по игрек";
//
// radioButton3
//
this->radioButton3->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->radioButton3->AutoSize = true;
this->radioButton3->Location = System::Drawing::Point(386, 135);
this->radioButton3->Name = L"radioButton3";
this->radioButton3->Size = System::Drawing::Size(44, 17);
this->radioButton3->TabIndex = 10;
this->radioButton3->TabStop = true;
this->radioButton3->Text = L"pi/6";
this->radioButton3->UseVisualStyleBackColor = true;
//
// radioButton4
//
this->radioButton4->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->radioButton4->AutoSize = true;
this->radioButton4->Location = System::Drawing::Point(484, 135);
this->radioButton4->Name = L"radioButton4";
this->radioButton4->Size = System::Drawing::Size(50, 17);
this->radioButton4->TabIndex = 11;
this->radioButton4->TabStop = true;
this->radioButton4->Text = L"5pi/6";
this->radioButton4->UseVisualStyleBackColor = true;
//
// radioButton5
//
this->radioButton5->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
this->radioButton5->AutoSize = true;
this->radioButton5->Location = System::Drawing::Point(349, 135);
this->radioButton5->Name = L"radioButton5";
this->radioButton5->Size = System::Drawing::Size(31, 17);
this->radioButton5->TabIndex = 12;
this->radioButton5->TabStop = true;
this->radioButton5->Text = L"0";
this->radioButton5->UseVisualStyleBackColor = true;
//
// textBox3
//
this->textBox3->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Right));
this->textBox3->Location = System::Drawing::Point(324, 391);
this->textBox3->Name = L"textBox3";
this->textBox3->Size = System::Drawing::Size(271, 20);
this->textBox3->TabIndex = 13;
this->textBox3->Text = L"Разработчик : Жохов Владислав группа МП-15А";
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->информацияToolStripMenuItem });
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(607, 24);
this->menuStrip1->TabIndex = 14;
this->menuStrip1->Text = L"menuStrip1";
//
// информацияToolStripMenuItem
//
this->информацияToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->оПрограммеToolStripMenuItem });
this->информацияToolStripMenuItem->Name = L"информацияToolStripMenuItem";
this->информацияToolStripMenuItem->Size = System::Drawing::Size(94, 20);
this->информацияToolStripMenuItem->Text = L"информация ";
this->информацияToolStripMenuItem->Click += gcnew System::EventHandler(this, &MyForm::информацияToolStripMenuItem_Click);
//
// оПрограммеToolStripMenuItem
//
this->оПрограммеToolStripMenuItem->Name = L"оПрограммеToolStripMenuItem";
this->оПрограммеToolStripMenuItem->Size = System::Drawing::Size(152, 22);
this->оПрограммеToolStripMenuItem->Text = L"о программе";
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::SystemColors::ActiveCaption;
this->ClientSize = System::Drawing::Size(607, 417);
this->Controls->Add(this->textBox3);
this->Controls->Add(this->radioButton5);
this->Controls->Add(this->radioButton4);
this->Controls->Add(this->radioButton3);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->button1);
this->Controls->Add(this->radioButton2);
this->Controls->Add(this->radioButton1);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->chart1);
this->Controls->Add(this->menuStrip1);
this->ForeColor = System::Drawing::SystemColors::ActiveCaptionText;
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->MainMenuStrip = this->menuStrip1;
this->Margin = System::Windows::Forms::Padding(2);
this->MaximizeBox = false;
this->MinimizeBox = false;
this->Name = L"MyForm";
this->Text = L"Поляризация ";
this->TransparencyKey = System::Drawing::Color::Gray;
this->WindowState = System::Windows::Forms::FormWindowState::Maximized;
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart1))->EndInit();
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
chart1->Series["1"]->Points->Clear();
double a1, a2, ex, ey, phi, b;
a1 = Convert::ToDouble(textBox1->Text);
a2 = Convert::ToDouble(textBox2->Text);
if (radioButton1->Checked == true)
b = 3.14;//pi
else if (radioButton2->Checked == true)
b = 1.57;//pi/2
else if (radioButton3->Checked == true)
b = 0.52;//pi/6
else if (radioButton4->Checked == true)
b = 2.16;//5pi/6
else if (radioButton5->Checked == true)
b = 0;//0
if (b == 3.14) {
for (double i = -a1; i < a1; i += 0.1) {
ey = -i;//linal
chart1->Series["1"]->Points->AddXY(i, ey);
}
}
if (b == 0) {
for (double i = -a1; i < a1; i += 0.1) {
ey = i;//linal
chart1->Series["1"]->Points->AddXY(i, ey);
}
}
if (( a1 == a2) && b == 1.57){
for (float i = -a1; i < a1; i += 0.1) {
ey = a2 * cos(acos(i / a1) - b);//round
chart1->Series["1"]->Points->AddXY(i, ey);
chart1->Series["1"]->Points->AddXY(i, -ey);
}
}
if ((a1 != a2) && b == 0.52) {
for (float i = -a1; i < a1; i += 0.1) {
ey = a2 * cos(acos(i / a1) - b);
//1and 3
chart1->Series["1"]->Points->AddXY(i, ey);
chart1->Series["1"]->Points->AddXY(-i, -ey);
}
}
if ((a1 != a2) && b == 2.16) {
for (float i = -a1; i < a1; i += 0.1) {
ey = a2 * cos(acos(i / a1) - b);
//1and 3
chart1->Series["1"]->Points->AddXY(i, ey);
chart1->Series["1"]->Points->AddXY(-i,-ey);
}
}
}
private: System::Void radioButton1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void информацияToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
/*About^ab = gcnew About();
ab->Show();*/
}
}
;
}
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Перевод документов на английский язык: Важность и ключевые аспекты
Есть команда состоящая из нескольких частей: действие -> объекты над которыми действие совершается
На Form есть DataGridView (в нём показывается одна строка) и WebBrowser
пишу бинарное дерево и наткнулся на очень непонятную мне ошибку, вот пример: