Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Drawing;
- namespace lab5_prog
- {
- public class BSplineCurve
- {
- int degree;
- DoublyLinkedList<ControlPoint> controlPoints;
- float[] knots;
- //BSplineCurve()
- //{
- // controlPoints = new DoublyLinkedList<ControlPoint>
- //}
- public void draw(Graphics g)
- {
- }
- public void addControlPoint(ControlPoint controlPoint)
- {
- controlPoints.Add(controlPoint);
- UpdatesNodes();
- }
- public void deleteControlPoint(ControlPoint controlPoint)
- {
- controlPoints.Remove(controlPoint);
- UpdatesNodes();
- }
- public void changeDegree(int degree)
- {
- }
- public void clear()
- {
- controlPoints.Clear();
- }
- private void UpdatesNodes()
- {
- knots = new float[controlPoints.Count + degree + 1];
- for(int i = 0; i < controlPoints.Count + degree + 1; i++)
- {
- if(i <= degree)
- {
- knots[i] = 0f;
- }
- if ((i > degree)&&(i < controlPoints.Count))
- {
- knots[i] = (float)(i - degree) / (controlPoints.Count - degree);
- }
- if (i >= controlPoints.Count)
- {
- knots[i] = 1f;
- }
- }
- }
- private PointF value(float u)
- {
- PointF point = new PointF(0, 0);
- for (int i = 0; i < controlPoints.Count; i++)
- {
- point.X += controlPoints[i].X * rec(u, i, degree + 1);
- point.Y += controlPoints[i].Y * rec(u, i, degree + 1);
- }
- return point;
- }
- private float rec(float u, int i, int k)
- {
- if(k != 1)
- {
- return (u - knots[i]) * rec(u, i, k - 1) / (knots[i + k - 1] - knots[i]) + (knots[i + k] - u)*rec(u, i + 1, k - 1)/(knots[i + k] - knots[i + 1]);
- }
- else
- {
- if(knots[i] <= u && u < knots[i+1])
- {
- return 1f;
- }
- else
- {
- return 0f;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement