/*!
 * \brief RectifyToVector::setUpResult
 * \param circle
 * \return
 */
bool RectifyToVector::setUpResult(Circle &circle){

    //get and check point
    if(!this->inputElements.contains(0) || this->inputElements[0].size() != 1){
        return false;
    }
    QPointer<Geometry> geometry = this->inputElements[0].at(0).geometry;
    if(geometry.isNull() || !geometry->getIsSolved() || !geometry->hasDirection()){
        return false;
    }

    //get the sense (positive or negative)
    double sense = 1.0;
    if(this->scalarInputParams.stringParameter.contains("sense")){
        if(this->scalarInputParams.stringParameter.value("sense").compare("negative") == 0){
            sense = -1.0;
        }
    }

    //get the direction to compare
    OiVec r_reference = geometry->getDirection().getVector();
    r_reference.normalize();
    OiVec r_circle = circle.getDirection().getVector();
    r_circle.normalize();

    //calculate the angle between both directions
    double angle = 0.0;
    OiVec::dot(angle, r_reference, r_circle);
    angle = qAbs(qAcos(angle));

    //invert the normal vector if the angle is greater than 90°
    if(angle > PI/2.0){
        r_circle = -1.0 * r_circle;
    }

    //invert the normal vector if sense is negative
    r_circle = sense * r_circle;

    //set result
    Direction direction = circle.getDirection();
    direction.setVector(r_circle);
    circle.setCircle(circle.getPosition(), direction, circle.getRadius());

    return true;

}
Ejemplo n.º 2
0
/*!
 * \brief Register::setUpResult
 * \param circle
 * \return
 */
bool Register::setUpResult(Circle &circle){

    //get and check plane
    if(!this->inputElements.contains(0) || this->inputElements[0].size() != 1){
        return false;
    }
    QPointer<Plane> plane = this->inputElements[0].at(0).plane;
    if(plane.isNull() || !plane->getIsSolved()){
        return false;
    }

    //get the position of the sphere and the plane and the normal vector
    OiVec n_plane = plane->getDirection().getVector();
    n_plane.normalize();
    OiVec x_plane = plane->getPosition().getVector();
    OiVec x_circle = circle.getPosition().getVector();

    //calculate the distance of the plane from the origin
    double d;
    OiVec::dot(d, x_plane, n_plane);
    if(d < 0.0){
        n_plane = -1.0 * n_plane;
        d = -d;
    }

    //calculate the distance of the sphere position from the plane
    double s;
    OiVec::dot(s, x_circle, n_plane);
    s = s - d;

    //project the sphere position into the plane
    x_circle = x_circle - s * n_plane;

    //set result
    Position position = circle.getPosition();
    position.setVector(x_circle);
    circle.setCircle(position, circle.getDirection(), circle.getRadius());

    return true;

}