Zobrazování 2D spline křivek
student.cpp
///////////////////////////////////////////////////////////////////////////////
// Soubor studentskych funkci
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// include
#include "main.h"
#include <assert.h>
#include <stdlib.h>
#include <iostream>
///////////////////////////////////////////////////////////////////////////////
// name spaces
using namespace std;
//Mocnina
double Power(double a, int b)
{
double result = 1.0;
for (int i = 0; i < b; ++i)
{
result *= a;
}
return result;
}
/////////////////// ZDE DOPLNTE IMPLEMENTACI ZA DOMACI UKOL ////////////////////
double N(int i, int k, double t, const K_NOT & U) {
double b;
if (k == 0) {
if ((t >= U[i]) && (t < U[i + 1])) {
return 1.0;
}
return 0.0;
}
if (!EQUAL_ZERO(U[i + k] - U[i])) {
b = (t - U[i]) / (U[i + k] - U[i]) * N(i, k - 1, t, U);
}
if (!EQUAL_ZERO(U[i + k + 1] - U[i + 1])) {
b += (U[i + k + 1] - t) / (U[i + k + 1] - U[i + 1]) * N(i + 1, k - 1, t, U);
}
return b;
}
void BSpline(int quality, const T_PointVector & points, T_PointVector & line_points , const BSplineDescription & bsplinedsc) {
double t;
int k;
double step = 1.0 / quality;
for (k = 0, t = 0.0; k <= quality; k++, t += step) {
if (t >= 1.0) {
t = 0.9;
}
int i;
double p;
double x;
double y;
for (i = 0, x = y = p = 0.0; i <= bsplinedsc.n; i++) {
double b = points[i].weight * N(i, bsplinedsc.k, t, bsplinedsc.U);
x += points[i].x * b;
y += points[i].y * b;
p += b;
}
if (EQUAL_ZERO(p)) {
x = y = 0.0;
} else {
x /= p;
y /= p;
}
line_points.push_back(S_Point(x, y));
}
}
////////////////////////////////////////////////////////////////////////////////