using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Drawing3d;
using Drawing3d.Math;
using Drawing3d.Devices;
using Drawing3d.Curves;
using Drawing3d.Editors;
namespace HelloWorld
{
public partial class Form1 : Form
{
Line MyLine = new Line(new xy(0,0), new xy(2.5,2));
Arc MyArc = new Arc(new xy(0,0),2,System.Math.PI/3,0,true);
Bezier MyBezier = new Bezier(new xy(0,0),new xy(1,1),new xy(2,-1),new xy(3,0));
QSpline MyQSpline = new QSpline(new xy(0,0),new xy(3,0), new xy(2.5,2),1.5);
BSpline MyBSpline = new BSpline();
Nurbs2d MyNurbs = new Nurbs2d();
public OpenGlDevice Device = new OpenGlDevice();
public Form1()
{
InitializeComponent();
}
void DrawPoints(xyArray Pts)
{
for (int i = 0; i < Pts.Count; i++)
Tools.drawMarker(Device, Pts[i]);
}
private void Form1_Load(object sender, EventArgs e)
{
Device.WinControl = this;
Device.OnPaint += new EventHandler(Device_OnPaint);
Device.Navigate = NavigateKind.ZoomRotateTrans;
Device.BackColor = Color.White;
Device.Lighting = false;
// Initialization of MyBspline & MyNurbs
xyArray ControlPoints = new xyArray(10);
ControlPoints[0] = new xy(0, 0);
ControlPoints[1] = new xy(0.25, 3 / 3f);
ControlPoints[2] = new xy(3 / 3f, 5 / 3f);
ControlPoints[3] = new xy(4 / 3f, 1 / 3f);
ControlPoints[4] = new xy(5 / 3f, 0);
ControlPoints[5] = new xy(7 / 3f, 0);
ControlPoints[6] = new xy(8 / 3f, -1 / 3f);
ControlPoints[7] = new xy(9 / 3f, 3 / 3f);
ControlPoints[8] = new xy(10 / 3f, 5 / 3f);
ControlPoints[9] = new xy(11 / 3f, 1 / 3f);
// Interpolationdegree
MyBSpline.Degree = 2;
MyBSpline.ControlPoints = ControlPoints;
// The same Controlpoints
MyNurbs.ControlPoints = ControlPoints;
// Interpolationdegree
MyNurbs.Degree = 3;
MyNurbs.Weights = new double[] { 1, 0.3, 1, 0.2, 4, 1, 1.3, 1, 2, 1 };
}
void Device_OnPaint(object sender, EventArgs e)
{
Device.FontName = "Modern";
xyArray Pts = new xyArray(0);
Device.FontSize = 0.4;
// Line
Device.PushMatrix();
Device.Translate(-5, 1, 0);
Device.drawCurve(MyLine);
Pts = new xyArray(2);
Pts[0] = MyLine.A;
Pts[1] = MyLine.B;
DrawPoints(Pts);
Device.drawText(new xyz(1, 2, 0), "Line", 0);
Device.PopMatrix();
// Arc
Device.PushMatrix();
Device.Translate(-1, 1, 0);
Device.drawCurve(MyArc);
Pts[0] = MyArc.A;
Pts[1] = MyArc.B;
DrawPoints(Pts);
Device.drawText(new xyz(1, 2, 0), "Arc", 0);
Device.PopMatrix();
// Bezier
Device.PushMatrix();
Device.Translate(3, 1, 0);
Device.drawCurve(MyBezier);
Device.drawText(new xyz(1, 2, 0), "Bezier", 0);
Pts = new xyArray(4);
Pts.FromArray(MyBezier.Points);
DrawPoints(Pts);
Device.PopMatrix();
// QSpline
Device.PushMatrix();
Device.Translate(-5, -1.5, 0);
Device.drawCurve(MyQSpline);
Device.drawText(new xyz(1, 2, 0), "QSpline", 0);
Pts = new xyArray(3);
Pts[0] = MyQSpline.A;
Pts[1] = MyQSpline.ControlPoint;
Pts[2] = MyQSpline.B;
DrawPoints(Pts);
// BSpline
Device.PopMatrix();
Device.PushMatrix();
Device.Translate(-1, -1.5, 0);
Device.drawCurve(MyBSpline);
Device.drawText(new xyz(1, 2, 0), "BSpline", 0);
DrawPoints(MyBSpline.ControlPoints);
Device.PopMatrix();
// Nurbs
Device.PushMatrix();
Device.Translate(3, -1.5, 0);
Device.drawCurve(MyNurbs);
Device.drawText(new xyz(1, 2, 0), "Nurbs", 0);
DrawPoints(MyBSpline.ControlPoints);
Device.PopMatrix();
}
}
}