Пример #1
0
toxi::geom::Polygon2D * toxi::geom::Polygon2D::smooth( const float & amount, const float & baseWeight )
{
	Vec2D centroid = getCentroid();
	int num = vertices.size();
	std::vector<Vec2D> filtered;
	for (int i = 0, j = num - 1, k = 1; i < num; i++) {
		Vec2D a = vertices.at(i);
		Vec2D dir = vertices.at(j).sub( a ).addSelf( vertices.at(k).sub( a ))
			.addSelf(a.sub( centroid).scaleSelf(baseWeight));
		filtered.push_back(a.add(dir.scaleSelf(amount)));
		j++;
		if (j == num) {
			j = 0;
		}
		k++;
		if (k == num) {
			k = 0;
		}
	}
	vertices.clear();

	for( auto it = filtered.begin(); it != filtered.end(); ++it ) 
	{
		vertices.push_back( *it );
	}

	return this;
}
Пример #2
0
toxi::geom::Polygon2D::Polygon2D( const Vec2D & baseA, const Vec2D & baseB, const int & res )
{
	double theta = -(toxi::math::MathUtils::PI - (toxi::math::MathUtils::PI * (res - 2) / res));
	Vec2D dir = baseB.sub( baseA);
	Vec2D prev = baseB;
	add( baseA );
	add( baseB );
	for (int i = 1; i < res - 1; i++) {
		Vec2D p = prev.add(dir.getRotated(theta * i));
		add(p);
		prev = p;
	}
}