Скачиваний:
11
Добавлен:
01.05.2014
Размер:
936 б
Скачать
#include <cassert>
#include "point.h"


class SpLine
{
	friend class Surface;
public:
	SpLine() : ready(false) {}
	SpLine(const Point& p1, const Point& p2,
		const Point& p3, const Point& p4)
	{ SetCurve(p1, p2, p3, p4); }

	void SetCurve(const Point& p1, const Point& p2,
		const Point& p3, const Point& p4)
	{
		ready = true;

		P[0] = p1;
		P[1] = p2;
		P[2] = p3;
		P[3] = p4;
	}
	Point GetPoint(double t)
	{
		assert(ready);
		double x, y, z;
		x = y = z = 0;

		double M[4][4] = { {-1, 3, -3, 1}, {3, -6, 3, 0}, 
		{-3, 3, 0, 0}, {1, 0, 0, 0} };
		double T[4] = { t * t * t, t * t, t, 1 };
		double R[4] = { 0 };

		int i, j;
		for (i = 0; i < 4; i++)
			for (j = 0; j < 4; j++)
				R[i] += T[j] * M[j][i];
		for (i = 0; i < 4; i++) {
			x += R[i] * P[i].x;
			y += R[i] * P[i].y;
			z += R[i] * P[i].z;
		}

		return Point(x, y, z);
	}
	
private:
	bool ready;
	Point P[4];
};

Соседние файлы в папке Лабораторная работа4