Открыть Электронные книги
Категории
Открыть Аудиокниги
Категории
Открыть Журналы
Категории
Открыть Документы
Категории
ЛАБОРАТОРНА РОБОТА 4
з курсу «Компьютерная графика с OpenGL»
Харків – 2019
10 вариант
ЦЕЛЬ РАБОТЫ: изучить математические методы и средства для реализации
графических примитивов.
ЗАДАНИЕ
Используя инструментальные средства, указанные преподавателем,
разработать программу для вывода кривых второго порядка на экран (в окно
Windows) с помощью отрезков. Для кривых, которые в варианте отмечены «++»,
найти и вывести на экран точки пересечения, если такие есть, с произвольным
отрезком, координаты которого задает пользователь.
ТЕОРЕТИЧЕСКИЕ СВЕДЕНИЯ
в виде
Положим
тогда и
следовательно, (1)
и
, (4-6)
где - параметр.
Рассматривая производные и :
, (4-7)
,
5
. (4-8)
Приращение параметра
Вычислим величины , и
МАШИННЫЙ ЛИСТИНГ
using System;
using System.ComponentModel;
using System.Data.Metadata.Edm;
using System.Drawing;
namespace glWinForm6
{
[ToolboxItem(true), ToolboxBitmap(typeof(RenderControl),
"RenderControl.bmp")]
public partial class RenderControl : OpenGL
{
private float WinWid = 60.0F;
private float WinHei = 60.0F;
private double x1 = 2, x2 = 1, y1 = 1, y2 = 3;
private double a = -30, b = 15;
private double n = 30, Omin, Omax, xmin = 0, xmax = 4;
public double A
{
get
{
7
return this.a;
}
set
{
this.a = value;
this.Invalidate();
}
}
public double B
{
get
{
return this.b;
}
set
{
this.b = value;
this.Invalidate();
}
}
public double X1
{
get
{
return this.x1;
}
set
{
this.x1 = value;
this.Invalidate();
}
}
public double X2
{
get
{
return this.x2;
}
set
{
this.x2 = value;
this.Invalidate();
}
}
public double Y1
{
get
{
return this.y1;
}
set
{
this.y1 = value;
this.Invalidate();
}
}
public double Y2
{
8
get
{
return this.y2;
}
set
{
this.y2 = value;
this.Invalidate();
}
}
public RenderControl() : base(false)
{
InitializeComponent();
}
double ch = Math.Cosh(bO);
double sh = Math.Sinh(bO);
9
glColor(Color.DarkBlue);
glLineWidth(2);
glBegin(GL_LINE_STRIP);
glVertex2d(x11, y11);
glVertex2d(x22, y22);
x11 = x22; y11 = y22;
}
glEnd();
glVertex2d(x22, -y22);
x11 = x22; y11 = -y22;
}
glEnd();
x11 = a * Math.Cosh(Omin);
y11 = 0;
glBegin(GL_LINE_STRIP);
glVertex2d(x11, -y11);
glVertex2d(x22, -y22);
x11 = x22; y11 = -y22;
}
glEnd();
glVertex2d(-x22, -y22);
x11 = -x22; y11 = -y22;
}
glEnd();
line();
glPointSize(3);
glBegin(GL_POINTS);
if (((0 <= t1) && (t1 <= 1)) && ((0 <= t2) && (t2 <= 1)))
{
glColor(Color.Yellow);
glVertex2d(xx, yy);
}
glEnd();
x11 = -x22; y11 = -y22;
}
glVertex2d(0, 15);
glVertex2d(-15, 0);
glVertex2d(15, 0);
glVertex2d(0, 15);
glVertex2d(0.1, 14.5);
glVertex2d(0, 15);
glVertex2d(-0.1, 14.5);
glVertex2d(15, 0);
glVertex2d(14.5, 0.1);
glVertex2d(15, 0);
glVertex2d(14.5, -0.1);
glEnd();
}
glBegin(GL_LINES);
//контур эллипса
private void StrokeEllipse(double xCenter, double yCenter, double rx,
double ry, int pointCount)
{
double step = 2 * Math.PI / pointCount;
// pointCount точек на его границе с шагом 2*PI/pointCount
glColor(Color.Red);
glBegin(GL_LINE_STRIP);
for (double angle = 0; angle < 2 * Math.PI; angle += step)
{
double dx = rx * Math.Cos(angle);
double dy = ry * Math.Sin(angle);
glVertex2d(dx + xCenter, dy + yCenter);
}
glEnd();
}
private void line()
{
glColor(Color.DarkGreen);
glBegin(GL_LINE_STRIP);
glVertex2d(x1, y1);
glVertex2d(x2, y2);
glEnd();
}
}
12
using System.Windows.Forms;
namespace glWinForm6
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
this.renderControl1.X1 = (double)this.numericUpDown1.Value;
this.renderControl1.Y1 = (double)this.numericUpDown2.Value;
this.renderControl1.X2 = (double)this.numericUpDown3.Value;
this.renderControl1.Y2 = (double)this.numericUpDown4.Value;
this.renderControl1.A = (double)this.numericUpDown5.Value;
this.renderControl1.B = (double)this.numericUpDown6.Value;
}
ЭКРАННАЯ ФОРМА
ТРЕБОВАНИЯ
№ Сложность Требования Баллы
1 Базовый уровень Установка изотропной системы 1
координат для
окна с изменяемыми размерами
2 Вывод кривых второго порядка в 2
соответствии с вариантом задания
3 Вывод отрезка и расчет его точек 2
пересечения с кривой второго порядка в
соответствии с вариантом