Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Vector2f[] BizierFunc(Vector2f start, Vector2f end, Vector2f focus)
- {
- //мне кажется где-то уже есть, но пусть будет
- Func<float, float, double> square = (float x1, float x2) => Math.Pow(x1 - x2, 2);
- Func<Vector2f, Vector2f, double> distance = (Vector2f first, Vector2f second) => Math.Sqrt(square(first.X, second.X) + square(first.Y, second.Y));
- //тут я на глаз считаю количество точек в кривой так что тоже нужно потестить
- var countOfPoints = (int) distance(start, end) / 10;
- var curve = new Vector2f[countOfPoints];
- var startCoefficent = 1 / countOfPoints;
- for (int i = 0; i < countOfPoints; i++)
- {
- //коэффицент от 0 до 1
- var coefficentBizie = startCoefficent * (i + 1);
- //формула уравнения
- curve[i] = (1 - coefficentBizie * coefficentBizie) * start +
- 2 * coefficentBizie * (1 - coefficentBizie) * focus +
- coefficentBizie * coefficentBizie * end;
- }
- return curve;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement