/*!
 * \brief IntersectLinePlane::isIntersection
 * \param line
 * \param plane
 * \return
 */
bool IntersectLinePlane::isIntersection(const QPointer<Line> &line, const QPointer<Plane> &plane){

    //scalar product of the lines's direction vector and the plane's normal vector
    double dot = 0.0;
    OiVec::dot(dot, line->getDirection().getVector(), plane->getDirection().getVector());
    if(dot > 0.0001 || dot < -0.0001){
        return true;
    }
    return false;

}
/*!
 * \brief IntersectLinePlane::setUpResult
 * \param point
 * \return
 */
bool IntersectLinePlane::setUpResult(Point &point){

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

    //check if line and plane intersect
    if(!this->isIntersection(line, plane)){
        emit this->sendMessage(QString("No intersection between line %1 and plane %2").arg(line->getFeatureName())
                               .arg(plane->getFeatureName()), eWarningMessage);
        return false;
    }

    //perform intersection
    OiVec l_v = line->getDirection().getVector(); //direction vector for line
    OiVec p_n = plane->getDirection().getVector(); //normal vector for plane
    OiVec l_x0 = line->getPosition().getVector(); //position vector for line
    OiVec p_x0 = plane->getPosition().getVector(); //position vector for plane
    p_n.normalize(); //normalize normal vector for plane
    double d = 0.0; //distance plane to origin
    OiVec::dot(d, p_x0, p_n);
    double h1, h2;
    OiVec::dot(h1, l_x0, p_n);
    OiVec::dot(h2, l_v, p_n);
    double lamda = (d - h1) / (h2);
    OiVec s = l_x0 + lamda * l_v;

    //set result
    Position section;
    section.setVector(s);
    point.setPoint(section);

    return true;

}
/*!
 * \brief RectifyToVector::setUpResult
 * \param plane
 * \return
 */
bool RectifyToVector::setUpResult(Plane &plane){

    //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_plane = plane.getDirection().getVector();
    r_plane.normalize();

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

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

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

    //set result
    Direction direction = plane.getDirection();
    direction.setVector(r_plane);
    plane.setPlane(plane.getPosition(), direction);

    return true;

}
Ejemplo n.º 4
0
/*!
 * \brief Register::setUpResult
 * \param sphere
 * \return
 */
bool Register::setUpResult(Sphere &sphere){

    //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_sphere = sphere.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_sphere, n_plane);
    s = s - d;

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

    //set result
    Position position = sphere.getPosition();
    position.setVector(x_sphere);
    Radius radius = sphere.getRadius();
    sphere.setSphere(position, radius);

    return true;

}