Advertisement
Lusien_Lashans

Безье кривая

May 19th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. public static Vector2f[] BizierFunc(Vector2f start, Vector2f end, Vector2f focus)
  2.         {
  3.             //мне кажется где-то уже есть, но пусть будет
  4.             Func<float, float, double> square = (float x1, float x2) => Math.Pow(x1 - x2, 2);
  5.             Func<Vector2f, Vector2f, double> distance = (Vector2f first, Vector2f second) => Math.Sqrt(square(first.X, second.X) + square(first.Y, second.Y));
  6.  
  7.             //тут я на глаз считаю количество точек в кривой так что тоже нужно потестить
  8.             var countOfPoints = (int) distance(start, end) / 10;
  9.  
  10.             var curve = new Vector2f[countOfPoints];
  11.             var startCoefficent = 1 / countOfPoints;
  12.  
  13.             for (int i = 0; i < countOfPoints; i++)
  14.             {
  15.                 //коэффицент от 0 до 1
  16.                 var coefficentBizie = startCoefficent * (i + 1);
  17.                 //формула уравнения
  18.                 curve[i] = (1 - coefficentBizie * coefficentBizie) * start +
  19.                             2 * coefficentBizie * (1 - coefficentBizie) * focus +
  20.                             coefficentBizie * coefficentBizie * end;
  21.             }
  22.  
  23.             return curve;
  24.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement