Beispiel #1
0
bool Map::swapSimplex(Simplex *s1, Simplex *s2) {
	int p1 = s1->whos(s2);
	int p2 = s2->whos(s1);
	if(p1 != -1 && p2 != -1) {
		Simplex *v1 = s1->getSimplex( (p1 + 1) % 3 );
		Simplex *v2 = s1->getSimplex( (p1 + 2) % 3 );
		Simplex *v3 = s2->getSimplex( (p2 + 1) % 3 );
		Simplex *v4 = s2->getSimplex( (p2 + 2) % 3 );

		Point *pt1 = s1->getPPoint( (p1 + 2) % 3 );
		Point *pt2 = s1->getPPoint( p1 );	
		Point *pt3 = s1->getPPoint( (p1 + 1) % 3 );
		Point *pt4 = s2->getPPoint( (p2 + 2) % 3 );

		if(inCircle(pt1, pt3, pt2, pt4)) {
			s1->setPoint(pt1, 0);
			s1->setPoint(pt2, 1);
			s1->setPoint(pt4, 2);

			s1->setAdjacent(v2, 0);
			s1->setAdjacent(v3, 1);
			s1->setAdjacent(s2, 2);

			s2->setPoint(pt1, 0);
			s2->setPoint(pt4, 1);
			s2->setPoint(pt3, 2);

			s2->setAdjacent(s1, 0);
			s2->setAdjacent(v4, 1);
			s2->setAdjacent(v1, 2);

			v1->setAdjaOfAdja(s1, s2, v1);
			v3->setAdjaOfAdja(s2, s1, v3);

			s1->resetDelta();
			s2->resetDelta();

			std::vector<Point*> temp;
			temp.reserve(s1->getNumberOfPoints() 
							+ s2->getNumberOfPoints());

			while(!s1->innerPointsEmpty()) 
				temp.push_back(s1->pop_front());

			while(!s2->innerPointsEmpty()) 
				temp.push_back(s2->pop_front());

			for(uint i = 0; i < temp.size(); i++) {
				if(s1->inside(temp[i]))
					s1->insert(temp[i]);
				else if(s2->inside(temp[i]))
					s2->insert(temp[i]);
			}

			_orderedSimplexes.shuffle(s1->getBinPos());
			_orderedSimplexes.shuffle(s2->getBinPos());
		}
	}
}
Beispiel #2
0
bool DialView::onTouchEvent(MotionEvent *event) {
    
    if (!isEnabled() || (!inCircle((int) event->getX(), (int) event->getY()) && mTouchState == TOUCH_STATE_RESTING)) {
        return false;
    }
    
    switch (event->getAction()) {
            
        case MotionEvent::ACTION_DOWN:
        {
            startTouch(event);
            break;
        }
            
        case MotionEvent::ACTION_MOVE:
        {
            if (mTouchState == TOUCH_STATE_CLICK) {
                startRotationIfNeeded(event);
            }
            
            if (mTouchState == TOUCH_STATE_ROTATE) {
                mVelocityTracker->addMovement(event);
                rotateChart(event->getX(), event->getY());
            }
            
            break;
        }
            
        case MotionEvent::ACTION_UP:
        {
            
            float velocity = 0;
            
            if (mTouchState == TOUCH_STATE_ROTATE) {
                
                mVelocityTracker->addMovement(event);
                mVelocityTracker->computeCurrentVelocity(PIXELS_PER_SECOND);
                
                velocity = calculateVelocity();
            }
            
            endTouch(velocity);
            
            break;
        }
            
        default:
        {
            endTouch(0);
            break;
        }
    }
    
    return true;
}
Beispiel #3
0
void Voronoi :: swapTest(Line &e,Point &p) {

    qDebug() << "Edge: "<<e.toString() << " P:"<<p.x() << " " << p.y();

    if ( (e.equals(ext1)) || (e.equals(ext2)) || (e.equals(ext3)) )   {
        return;
    }
    else {

        bool exists = false;
        Point d = findVertexOnTheRight(e,p,exists);
        if (exists)  {

            qDebug() << "Vertex on the right" <<  d.x() << " " << d.y();
            Point eA = e.getA();
            Point eB = e.getB();
            if ( inCircle(p, eA, eB, d) ) {

                qDebug() << "Is in circle, flipping";
                flip(e,p,d);
                Line l1,l2;
                l1.setA(eA);
                l1.setB(d);

                l2.setA(d);
                l2.setB(eB);

                swapTest(l1, p);
                swapTest(l2, p);

            }

        }
        else {
            qDebug() << "No vertex on the right";
        }

    }
}
bool Triangle::doitSwapper(QVector<QPointF>& points , QVector<Triangle>& triangles, int& id_autre)
{

    // verifier si les triangles sont adjacents

    //----------------- vérifier si id_this figure dans la liste des adjacents de id_autre
    if(!this->estAdjacent(triangles ,  id_autre )) {
        return false;
    }else{
        if(!triangles[id_autre].estAdjacent(triangles , this->id )){
            return false;
        }else{
            // on est sûr que les triangles sont adjacents
            // il y a donc une chance de faire un swap

            // 1 - chercher le point non commun dans le triangle autre et présent dans "this"
            int a = triangles[id_autre].nonCommun(this->id) ;
            return inCircle( a , points ) ;

        }
    }
}
dVoxelArray * MakeHockeyPuck(float robot_cost, float robot_deform)
{
    printf("Building the hockey puck robot...\n");
    dVoxelArray * Manipulator = AllocateDVoxelArray(16, 16, 5, 8, 8, 2, 0.0, 1.0);
    //Color the manipulator red and make it rigid
    for (int i = 0; i < Manipulator->xDim; i++)
    {
        for (int j = 0; j < Manipulator->yDim; j++)
        {
            for (int k = 0; k < Manipulator->zDim; k++)
            {
                if (inCircle(7.5, 7.5, i, j, 8.0))
                {
                    Manipulator->dVoxels[i][j][k].deformability = robot_deform;
                    Manipulator->dVoxels[i][j][k].sensitivity = robot_cost;
                    Manipulator->dVoxels[i][j][k].A = 128;
                    Manipulator->dVoxels[i][j][k].R = 255;
                }
            }
        }
    }
    return Manipulator;
}
void Triangulation2D_Delaunay::InsertPoint(Point* newPoint) {
	if(_triangles.empty()) {
		// 1er point
		if(_points.empty()) {
			_points.push_back(newPoint);
		}
		// 2em point
		else if(_points.size() == 1) {
			_points.push_back(newPoint);
			_edges.push_back(new Line(_points[0], newPoint));
		}
		// 3+em point
		else {
			_points.push_back(newPoint);
			// Si le point est colinéaire aux autres
			if(isOnLine(_edges[0], newPoint)) {
				// Si le point est à l'extremité "basse" des points colinéaires
				Point* minPoint = getMinCoordinates(_points);
				Point* maxPoint = getMaxCoordinates(_points);

				if(newPoint->getX() < minPoint->getX() || (newPoint->getX() == minPoint->getX() && newPoint->getY() < minPoint->getY())) {
					_edges.push_back(new Line(newPoint, nullptr));
				}
				// Si le point est à l'extremité "haute" des points colinéaires
				else if(newPoint->getX() > maxPoint->getX() || (newPoint->getX() == maxPoint->getX() && newPoint->getY() > maxPoint->getY())) {
					_edges.push_back(new Line(nullptr, newPoint));
				}
				// Si le point est en plein milieu
				// On update l'ancienne arete et on ajoute une nouvelle arête
				else {
					Point* pointBefore = getMiddleCoordinates(_points, newPoint);
					for(auto edge : _edges) {
						if(edge->getStartPoint() == pointBefore) {
							_edges.push_back(new Line(newPoint, edge->getEndPoint()));
							edge->setEndPoint(newPoint);
							break;
						}
					}

				}

				delete minPoint;
				delete maxPoint;
			}
			// Si le point n'est pas colinéaire
			// (on passera ici qu'une fois normalement)
			else {
				for(auto point : _points) {
					Line* tempLine = new Line(point, newPoint);
					_edges.push_back(tempLine);
					point->setLine(tempLine);
				}

				for(auto edge : _edges) {
					Line* tempLineA = edge->getStartPoint()->getLine();
					Line* tempLineB = edge->getEndPoint()->getLine();
					// Peut etre à l'envers
					_triangles.push_back(new Triangle(edge, tempLineA, tempLineB));
					// ou 
					//_triangles.push_back(new Triangle(edge, tempLineB, tempLineA));
					// en fonction de la position de newPoint ?
				}
			}
		}
	}
	// Y'a deja des triangles
	else {
		_points.push_back(newPoint);
		// Si le point est dans un triangle
		bool inTriangle = false;
		Triangle* triangleContainingPoint = nullptr;
		std::vector<Line*> edges;

		std::vector<Triangle*>::iterator it;
		for(it = _triangles.begin(); it != _triangles.end(); it++) {
			Triangle* triangle = *it;
			if(PointInTriangle(*newPoint, *triangle->getPointA(), *triangle->getPointB(), *triangle->getPointC())) {
				inTriangle = true;
				triangleContainingPoint = triangle;
				break;
			}
		}
		if(inTriangle) {
			_triangles.erase(it);
			edges.push_back(triangleContainingPoint->LineA());
			edges.push_back(triangleContainingPoint->LineB());
			edges.push_back(triangleContainingPoint->LineC());
		}
		else {
			//TODO: déterminer la liste des aretes vues par le point
			// Avec l'enveloppe c'est plus opti
			for(auto edge : _edges) {
				Point normal(-(edge->getEndPoint()->getY() - (edge->getStartPoint()->getY())), edge->getEndPoint()->getX() - (edge->getStartPoint())->getX());
				Point edgee(newPoint->getX() - edge->getEndPoint()->getX(), newPoint->getY() - edge->getEndPoint()->getY());
				double dot = dotProduct(normal, edgee);
				if(dot < 0) {
					edges.push_back(edge);
				}
			}
		}

		while(!edges.empty()) {
			Line* a = edges.back();
			edges.pop_back();

			bool pointInCircle = false;
			std::vector<Triangle*>::iterator it2;
			for(it2 = _triangles.begin(); it2 != _triangles.end(); it2++) {
				Triangle* triangle2 = *it2;
				if(inCircle(triangle2->getPointA(), triangle2->getPointB(), triangle2->getPointC(), newPoint)) {
					pointInCircle = true;
					break;
				}
			}

			// Si l'arete a un triangle incident t dont le cercle circonscrit contient newPoint, suprimer le triangle t et l'arete a et ajouter les 2 autres aretes du triangle à la liste
			if(pointInCircle) {
				std::cout << "je passe jamais !" << std::endl;
				Triangle* triangle = *it;
				edges.erase(edges.begin());
				if(triangle->LineA() != a) {
					edges.push_back(triangle->LineA());
				}
				if(triangle->LineB() != a) {
					edges.push_back(triangle->LineB());
				}
				if(triangle->LineC() != a) {
					edges.push_back(triangle->LineC());
				}
				_triangles.erase(it);
			}
			else {
				// creer aretes start - new et end - new et le triangle a a1 a2 (ou a2 a1 a)
				Line* a1 = new Line(a->getStartPoint(), newPoint);
				Line* a2 = new Line(a->getEndPoint(), newPoint);
				_edges.push_back(a1);
				_edges.push_back(a2);
				_triangles.push_back(new Triangle(a, a1, a2));
			}
		}
	}
}
Beispiel #7
0
inline static std::pair<std::pair<long double, long double>, long double> minCircle(unsigned int s, unsigned int e, int q1, int q2, int q3)
{
	std::pair<std::pair<long double, long double>, long double> res;
	std::random_shuffle(sPoint + s, sPoint + e);
	if(q3 != -1) // GOT A TRIPLE
	{
		res.first.first = ((sPoint[q2].first * sPoint[q2].first * sPoint[q3].second + sPoint[q2].second * sPoint[q2].second * sPoint[q3].second - sPoint[q1].first * sPoint[q1].first * sPoint[q3].second + sPoint[q1].first * sPoint[q1].first * sPoint[q2].second - sPoint[q1].second * sPoint[q1].second * sPoint[q3].second + sPoint[q1].second * sPoint[q1].second * sPoint[q2].second + sPoint[q1].second * sPoint[q3].first * sPoint[q3].first + sPoint[q1].second * sPoint[q3].second * sPoint[q3].second - sPoint[q1].second * sPoint[q2].first * sPoint[q2].first - sPoint[q1].second * sPoint[q2].second * sPoint[q2].second - sPoint[q2].second * sPoint[q3].first * sPoint[q3].first - sPoint[q2].second * sPoint[q3].second * sPoint[q3].second) / (sPoint[q1].second * sPoint[q3].first - sPoint[q1].second * sPoint[q2].first - sPoint[q2].second * sPoint[q3].first - sPoint[q3].second * sPoint[q1].first + sPoint[q3].second * sPoint[q2].first + sPoint[q2].second * sPoint[q1].first)) / 2;
		res.first.second = ((-sPoint[q1].first * sPoint[q3].first * sPoint[q3].first - sPoint[q1].first * sPoint[q3].second * sPoint[q3].second + sPoint[q1].first * sPoint[q2].first * sPoint[q2].first + sPoint[q1].first * sPoint[q2].second * sPoint[q2].second + sPoint[q2].first * sPoint[q3].first * sPoint[q3].first + sPoint[q2].first * sPoint[q3].second * sPoint[q3].second - sPoint[q2].first * sPoint[q2].first * sPoint[q3].first - sPoint[q2].second * sPoint[q2].second * sPoint[q3].first + sPoint[q1].first * sPoint[q1].first * sPoint[q3].first - sPoint[q1].first * sPoint[q1].first * sPoint[q2].first + sPoint[q1].second * sPoint[q1].second * sPoint[q3].first - sPoint[q1].second * sPoint[q1].second * sPoint[q2].first) / (sPoint[q1].second * sPoint[q3].first - sPoint[q1].second * sPoint[q2].first - sPoint[q2].second * sPoint[q3].first - sPoint[q3].second * sPoint[q1].first + sPoint[q3].second * sPoint[q2].first + sPoint[q2].second * sPoint[q1].first)) / 2;
		res.second = dist(res.first, sPoint[q2]);

		return res;
	}

	else if(q2 != -1)
	{
		res.first = std::make_pair(
			(sPoint[q1].first + sPoint[q2].first) / 2,
			(sPoint[q1].second + sPoint[q2].second) / 2
		);

		res.second = dist(res.first, sPoint[q1]);
	}

	else if(q1 != -1)
	{
		res.first = std::make_pair(
			(sPoint[q1].first + sPoint[s].first) / 2,
			(sPoint[q1].second + sPoint[s].second) / 2
		);

		res.second = dist(res.first, sPoint[q1]);
		if(e == s + 1)
			return res;
	}

	else if(e == s + 1)
	{
		res.first = sPoint[s];
		res.second = 0;
		return res;
	}

	else
	{
		res.first = std::make_pair(
			(sPoint[s].first + sPoint[s + 1].first) / 2,
			(sPoint[s].second + sPoint[s + 1].second) / 2
			);

		res.second = dist(res.first, sPoint[s]);
	}

	for(unsigned int p = s; p < e; ++ p)
	{
		if(inCircle(res, sPoint[p]))
			continue;

		if(q2 != -1)
			res = minCircle(s, p, q1, q2, p);

		else if(q1 != -1)
			res = minCircle(s, p, q1, p);

		else
			res = minCircle(s, p, p);
	}

	return res;
}
Beispiel #8
0
bool Subdivision::shouldSwap(const Vec2& x, Edge *e)
{
        Edge *t = e->Oprev();
        return inCircle(e->Org(), t->Dest(), e->Dest(), x);
}