Esempio n. 1
0
Prefix getPrefixFromWC(VEC coord)
{
	Prefix pfx;
	Orientation ori(SYMMETRY_HEXAGONAL);

	if (coord.y > 0)
	{
		if (!(coord * VEC(COS30, -SIN30) > 0 && coord.x>0)){
			ori.rotate(VP);
			pfx.rotate(VP);
		}
	} else {
		ori.rotate(VN);
		pfx.rotate(VN);
	}

	VEC vertexpoint_[3];
	double dist[3];
	vertexpoint_[0] = ori.getWCFromOC(VEC(0, 0)) - coord;
	vertexpoint_[1] = ori.getWCFromOC(VEC(COS30, -SIN30)) - coord;
	vertexpoint_[2] = ori.getWCFromOC(VEC(COS30, SIN30)) - coord;

	for (int i=0; i<3; i++)
		dist[i] = vertexpoint_[i]*vertexpoint_[i];
	

	if (dist[1] < dist[0])
		pfx.rotate((dist[2]<dist[1])? FN: FP);
	else if (dist[2] < dist[0])
		pfx.rotate(FN);


	for (int i=0; i<3; i++)
	{
		if (ori.getOCFromWC(coord).x > COS30)
			return Prefix();
	}

	return pfx;		
}
Esempio n. 2
0
bool SymmetryObject::addNewEP(int sluten)
{
	//cout << "i addfacetobe so is sluten = " << sluten << endl;
			//vector<edge>::iterator ite = E_ToBe.end();
	int sizE = E.size();

	//		Fixa:
	// Rootera tillbaka ytan så att början
	//och slutet alltid rör  en rootPoint.
	Prefix draBortPfxInv = E_ToBe[0].fr.Pfx;//.getSize();
	cout << "The following prefix ska dras away" << endl;
	draBortPfxInv.print();
	draBortPfxInv = draBortPfxInv.getInverse();

	for (unsigned int i=0; i<E_ToBe.size()-1; i++)
	{
		edge edgeToPushBack;

		Prefix enAnnanPrefixIgen = draBortPfxInv;
		enAnnanPrefixIgen.rotate(E_ToBe[i].fr.Pfx);
		enAnnanPrefixIgen.simplify();
		edgeToPushBack.fr.Pfx = enAnnanPrefixIgen;
		edgeToPushBack.fr.index = E_ToBe[i].fr.index;

		enAnnanPrefixIgen = draBortPfxInv;
		enAnnanPrefixIgen.rotate(E_ToBe[i].to.Pfx);
		enAnnanPrefixIgen.simplify();
		edgeToPushBack.to.Pfx = enAnnanPrefixIgen;
		edgeToPushBack.to.index = E_ToBe[i].to.index;

		Prefix PfxNext;
		Prefix PfxPrev;

		switch (sluten) {
			case NOT_CENTERED: {
				edgeToPushBack.next = Edge(PfxNext, (i==E_ToBe.size()-2? sizE: sizE + i + 1));
				edgeToPushBack.prev = Edge(PfxPrev, (i==0? sizE + E_ToBe.size() - 2: sizE + i - 1));
				break;
			}
			case VERTEX_CENTERED: {

				if (i==0)
					PfxPrev.rotate(VN);
				if (i==E_ToBe.size()-2)
					PfxNext.rotate(VP);
				edgeToPushBack.next = Edge(PfxNext, (i==E_ToBe.size()-2? sizE: sizE + i + 1));
				edgeToPushBack.prev = Edge(PfxPrev, i==0? sizE + E_ToBe.size() - 2: sizE + i - 1);
				//edgeToPushBack.next = (i==E_ToBe.size()-2? Edge(Pfx, sizE): Edge(Prefix(), sizE + i + 1));
				break;
			}
			case EDGE_CENTERED: {
				Prefix cpPrefixHelvete;

				cpPrefixHelvete = E_ToBe[E_ToBe.size()-1].fr.Pfx;
				cpPrefixHelvete.rotate(draBortPfxInv);

				cout << "when it is done, it becomasar: ";
				cpPrefixHelvete.print();
				cout << endl;

				if (i==0) {
					PfxPrev = cpPrefixHelvete;
				}


				if (i==E_ToBe.size()-2) {
					PfxNext = cpPrefixHelvete;
				}

				edgeToPushBack.next = Edge(PfxNext, (i==E_ToBe.size()-2? sizE: sizE + i + 1));
				edgeToPushBack.prev = Edge(PfxPrev, (i==0? sizE + E_ToBe.size() - 2: sizE + i - 1));
				break;
			}
			case FACE_CENTERED: {
				Prefix PfxNext;
				Prefix PfxPrev;

				if (i==0)
					PfxPrev.rotate(FN);
				if (i==E_ToBe.size()-2)
					PfxNext.rotate(FP);
				edgeToPushBack.next = Edge(PfxNext, (i==E_ToBe.size()-2? sizE: sizE + i + 1));
				edgeToPushBack.prev = Edge(PfxPrev, (i==0? sizE + E_ToBe.size() - 2: sizE + i - 1));
				break;
			}
			default:
				cout << "symmetryObject.cpp\tHIT SKA DEN INTE KOMMA!!!!!!!!!!!" << endl;
				break;
		}

			// kolla genom om man kan hitta någon opposite
		cout << endl;
		//int kortastePrefix = 10000000;
		edgeToPushBack.oppo.index = -1;
		//edgeToPushBack.





			// kolla genom om man kan hitta någon opposite, IGEN
		if (edgeToPushBack.oppo.index == -1) {
			for (unsigned int j=0; j<E.size(); j++)
			{
				Prefix oppositeOfPrefix;
				//if (E[j].isOppositeOf(E_ToBe[i], &oppositeOfPrefix)) {
				if (E[j].isOppositeOf(edgeToPushBack, &oppositeOfPrefix)) {
					edgeToPushBack.oppo = Edge(oppositeOfPrefix.getInverse(), j);
					E[j].oppo = Edge(oppositeOfPrefix, i + sizE);

					break;
				}
			}
		}
		//cout << "a" << endl;

		Prefix oppositeOfPrefix;
		if (edgeToPushBack.oppo.index == -1)
		{
			//if (E_ToBe[i].isOppositeOf(E_ToBe[i], &oppositeOfPrefix)) {
			if (E_ToBe[i].isOppositeOf(edgeToPushBack, &oppositeOfPrefix)) {
				edgeToPushBack.oppo = Edge(oppositeOfPrefix.getInverse(), i + sizE);
			}
		}

		E.push_back(edgeToPushBack);
	}

	F.push_back(face(sizE, E.size() - sizE, sluten));
	cout << "          *****************************************            " << endl;
	cout << "tjena nu is jag here" << endl;
		// uppdatera GUI:et
	char strToSend[200];
		// id, first edge, num of edges, type, görasigplatt-styrka
	snprintf(strToSend, 200, "%d,%d,%d,%d", F.size()-1, sizE, E.size() - sizE, sluten);
	cout << "detta skickas when face skapas: " << strToSend << endl;

	E_ToBe.clear();
	printAll();
	return true;
}
Esempio n. 3
0
	// returns true if e is opposite edge. If pfx != null, pfx
bool edge::isOppositeOf(const edge &e, Prefix *pfx)
{
		// avsluta om inte ens punkterna stämmer
	if (fr.index != e.to.index || to.index != e.fr.index)
		return false;

	Prefix X;

		//
	cout << " ** drive isOppositeOf" << endl;
	cout << "this: " << endl;
	this->print();
	cout << endl << "edge e: " << endl;
	e.print();


	switch(fr.index)
	{
		case VERTEX_CENTERED: {
			cout << "a" << endl;

				// fr = X e.to
			X = fr.Pfx;
			X.rotate(e.to.Pfx.getInverse());
			Point e_fr(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

				// fr [VP] = X e.to
			X = fr.Pfx;
			X.rotate(VP);
			X.rotate(e.to.Pfx.getInverse());
			e_fr = Point(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

				// fr [VN] = X e.to
			X = fr.Pfx;
			X.rotate(VN);
			X.rotate(e.to.Pfx.getInverse());
			e_fr = Point(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

			cout << "a" << endl;
			break;
		}
		case EDGE_CENTERED: {
			cout << "b" << endl;

			X = fr.Pfx;
			X.rotate(e.to.Pfx.getInverse());
			Point e_fr(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

				// fr [VP] = X e.to
			X = fr.Pfx;
			X.rotate(VP);
			X.rotate(FP);
			X.rotate(e.to.Pfx.getInverse());
			e_fr = Point(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

			break;
		}
		case FACE_CENTERED: {
			cout << "c" << endl;

				// fr = X e.to
			X = fr.Pfx;
			X.rotate(e.to.Pfx.getInverse());
			Point e_fr(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

				// fr [FP] = X e.to
			X = fr.Pfx;
			X.rotate(FP);
			X.rotate(e.to.Pfx.getInverse());
			e_fr = Point(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

				// fr [FN] = X e.to
			X = fr.Pfx;
			X.rotate(FN);
			X.rotate(e.to.Pfx.getInverse());
			e_fr = Point(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}

			cout << "c" << endl;
			break;
		}
		default: {

			cout << "D" << endl;
			X = fr.Pfx;
			X.rotate(e.to.Pfx.getInverse());
			Point e_fr(X * e.fr.Pfx, e.fr.index);
			if (to.equalTo(e_fr))	{*pfx = X;	return true;}
			cout << "D" << endl;
			break;
		}
	}


	//pfx->R.clear();
	return false;
}