Advertisement
Guest User

Untitled

a guest
Nov 29th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Drawing;
  7.  
  8. namespace lab5_prog
  9. {
  10. public class BSplineCurve
  11. {
  12. int degree;
  13. DoublyLinkedList<ControlPoint> controlPoints;
  14. float[] knots;
  15.  
  16. //BSplineCurve()
  17. //{
  18. // controlPoints = new DoublyLinkedList<ControlPoint>
  19. //}
  20.  
  21. public void draw(Graphics g)
  22. {
  23.  
  24. }
  25. public void addControlPoint(ControlPoint controlPoint)
  26. {
  27. controlPoints.Add(controlPoint);
  28. UpdatesNodes();
  29. }
  30. public void deleteControlPoint(ControlPoint controlPoint)
  31. {
  32. controlPoints.Remove(controlPoint);
  33. UpdatesNodes();
  34. }
  35. public void changeDegree(int degree)
  36. {
  37.  
  38. }
  39. public void clear()
  40. {
  41. controlPoints.Clear();
  42. }
  43. private void UpdatesNodes()
  44. {
  45. knots = new float[controlPoints.Count + degree + 1];
  46. for(int i = 0; i < controlPoints.Count + degree + 1; i++)
  47. {
  48. if(i <= degree)
  49. {
  50. knots[i] = 0f;
  51. }
  52. if ((i > degree)&&(i < controlPoints.Count))
  53. {
  54. knots[i] = (float)(i - degree) / (controlPoints.Count - degree);
  55. }
  56. if (i >= controlPoints.Count)
  57. {
  58. knots[i] = 1f;
  59. }
  60. }
  61. }
  62. private PointF value(float u)
  63. {
  64. PointF point = new PointF(0, 0);
  65.  
  66. for (int i = 0; i < controlPoints.Count; i++)
  67. {
  68. point.X += controlPoints[i].X * rec(u, i, degree + 1);
  69. point.Y += controlPoints[i].Y * rec(u, i, degree + 1);
  70. }
  71. return point;
  72. }
  73. private float rec(float u, int i, int k)
  74. {
  75. if(k != 1)
  76. {
  77. 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]);
  78. }
  79. else
  80. {
  81. if(knots[i] <= u && u < knots[i+1])
  82. {
  83. return 1f;
  84. }
  85. else
  86. {
  87. return 0f;
  88. }
  89. }
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement