/*
Order vertices (1st arg) based on the visual angle seen from a click point (3rd arg).
The 2nd argument carries contour information.
*/
vector<Vertex<FragmentInfo>*>
orderVertices(vector<Vertex<FragmentInfo>*>& vertices,
			  vector<ContourEQW>& contours, 
			  CParticleF& click)
{
	vector<Vertex<FragmentInfo>*> ordered;
	vector<indexedData> vdata;
	for(int i=0; i<vertices.size(); ++i)
	{
		int c = vertices[i]->key.contourID;
		int p = vertices[i]->key.pointID;
		float x = contours[c].X[p];
		float y = contours[c].Y[p];
		indexedData d;
		d.data = GetVisualDirection(x, y, click.m_X, click.m_Y);
		if(d.data < 0)
		{
			 d.data += 2*PI;
		}
		d.index = i;
		vdata.push_back(d);
		vertices[i]->key.angle = d.data;
	}
	sort(vdata.begin(), vdata.end());
	for(int i=0; i<vdata.size(); ++i)
	{
		ordered.push_back(vertices[vdata[i].index]);
	}
	return ordered;
}
bool GetOrientation(FragmentInfo& start, 
					FragmentInfo& dest,
					CParticleF& click,
					vector<ContourEQW>& contours)
{
	float x1 = contours[start.contourID].X[start.pointID];
	float y1 = contours[start.contourID].Y[start.pointID];
	float x2 = contours[dest.contourID].X[dest.pointID];
	float y2 = contours[dest.contourID].Y[dest.pointID];
	float d1 = GetVisualDirection(x1, y1, click.m_X, click.m_Y);
	float d2 = GetVisualDirection(x2, y2, click.m_X, click.m_Y);
	if(d2 < d1)
	{
		d2 += 2*PI;
	}
	if(d2-d1 < PI) return true;
	else return false;
}
예제 #3
0
/*
return a unit vector that bisects the angle formed by three points: a-o-b.
*/
CParticleF
bisector(CParticleF& o, CParticleF& a, CParticleF& b)
{
	CParticleF x = NormalizedDirection(a, o);
	CParticleF y = NormalizedDirection(b, o);
	CParticleF z((x.m_X + y.m_X) / 2, (x.m_Y + y.m_Y) / 2);
	float vx = z.m_X;
	float vy = z.m_Y;
	float len0 = sqrt(vx*vx + vy*vy);
	if (len0 <= 1.0e-5) //this is a colinear point. 
	{
		float ang = GetVisualDirection(b.m_X, b.m_Y, a.m_X, a.m_Y) - PI / 2.0;
		vx = cos(ang);
		vy = sin(ang);
	}
	else
	{
		vx = vx / len0;
		vy = vy / len0;
	}
	CParticleF bs(o.m_X + vx, o.m_Y + vy);

	//There are two bisector directions. 
	//We consistently choose one that is in clock-wise direction.
	vector<CParticleF> pnts(4);
	pnts[0] = o;
	pnts[1] = a;
	pnts[2] = bs;
	pnts[3] = b;
	if (ClockWise(pnts)<0)
	{
		vx = -vx;
		vy = -vy;
	}
	return CParticleF(vx, vy);
}