bool IntersectShape::intersectXRect(const Ray &ray, const double &x, const Interval &yrange, const Interval &zrange, double &t)
{
    if (IntersectShape::intersectXPlane(ray, x, t))
        return yrange.contains(ray.p.y + t * ray.d.y) &&
               zrange.contains(ray.p.z + t * ray.d.z);
    else
        return false;
}
bool IntersectShape::intersectZRect(const Ray &ray, const double &z, const Interval &xrange, const Interval &yrange, double &t)
{
    if (IntersectShape::intersectZPlane(ray, z, t))
        return yrange.contains(ray.p.y + t * ray.d.y) &&
               xrange.contains(ray.p.x + t * ray.d.x);
    else
        return false;
}
bool IntersectShape::intersectYRect(const Ray &ray, const double &y, const Interval &xrange, const Interval &zrange, double &t)
{
    if (IntersectShape::intersectYPlane(ray, y, t))
        return xrange.contains(ray.p.x + t * ray.d.x) &&
               zrange.contains(ray.p.z + t * ray.d.z);
    else
        return false;
}
Esempio n. 4
0
void TreeNode::insert(Interval i){
	if(i.contains(center)){
		left_end.push_back(i.a);
		right_end.push_back(i.b);
		return;
	}

	if(i.b < center){
		//interval is left to center
		if(!left)
			left = new TreeNode(i.middle());
		left->insert(i);
	}
	else{
		//interval is right to center
		if(!right)
			right = new TreeNode(i.middle());
		right->insert(i);
	}
}
Esempio n. 5
0
    virtual void draw(cairo_t *cr, std::ostringstream *notify, int width, int height, bool save, std::ostringstream *timer_stream) {
        cairo_set_source_rgba (cr, 0., 0., 0, 1);
        cairo_set_line_width (cr, 1);
        
        if(0) {
            Path path;
            path = Path(path_handles.pts[0]);
            D2<SBasis> c = handles_to_sbasis(path_handles.pts.begin(), 2);
            path.append(c);
	
            cairo_save(cr);
            cairo_path(cr, path);
            cairo_set_source_rgba (cr, 0., 1., 0, 0.3);
            cairo_set_line_width (cr, 3);
            cairo_stroke(cr);
            cairo_restore(cr);

            //double w = exp(sliders[0].value());
        }
        Point A = path_handles.pts[0];
        Point B = path_handles.pts[1];
        Point C = path_handles.pts[2];
      
        if(1) {
            QuadraticBezier qb(A, B, C);
            //double abt = qb.nearestTime(oncurve.pos);
            //oncurve.pos = qb.pointAt(abt);
      
            RatQuad rq = RatQuad::fromPointsTangents(A, B-A, oncurve.pos, C, B -C); //( A, B, C, w);
	
            cairo_save(cr);
            cairo_set_source_rgba (cr, 0., 0., 0, 1);
            cairo_set_line_width (cr, 1);
            draw_ratquad(cr, rq);
            //cairo_d2_sb(cr, rq.hermite());
            cairo_stroke(cr);
            cairo_restore(cr);
        }      

        if(0) {
            RatQuad rq = RatQuad::circularArc(A, B, C);
	
            cairo_save(cr);
            cairo_set_source_rgba (cr, 0., 0., 0, 1);
            cairo_set_line_width (cr, 1);
            RatQuad a, b;
            rq.split(a,b);
            cairo_curve(cr, a.toCubic());
            cairo_curve(cr, b.toCubic());
            cairo_stroke(cr);
            cairo_restore(cr);
        }      

        Rect screen_rect(Interval(10, width-10), Interval(10, height-10));
        Line cutLine(cutting_plane.pts[0], cutting_plane.pts[1]);
        //double dist;
        //Point norm = cutLine.normalAndDist(dist);
      
        const unsigned N = 3;
        xAx sources[N] = {
            xAx::fromPoint(A)*(exp(-sliders[0].value())),
            xAx::fromPoint(B)*(exp(-sliders[1].value())),
            xAx::fromPoint(C)*(exp(-sliders[2].value()))
            //xAx::fromLine(Line(A, oncurve.pos))
        };
        for(unsigned i = 0; i < N; i++) {
            //*notify << sources[i] << "\n";
        }
        for(unsigned i = 0; i < N; i++) {
            for(unsigned j = i+1; j < N; j++) {
                xAx Q = sources[i]-sources[j];
                *notify << Q << " is a " << Q.categorise() << "\n";
            }
        }
        {
            cairo_save(cr);
            cairo_set_source_rgba(cr, 0, 0, 1, 0.5);
            
            ::draw(cr, (sources[0]-sources[1]), screen_rect);
            ::draw(cr, (sources[0]-sources[2]), screen_rect);
            ::draw(cr, (sources[1]-sources[2]), screen_rect);
            cairo_restore(cr);
        }
        {
            string os;
            for(unsigned i = 0; i < N; i++) {
                for(unsigned j = i+1; j < N; j++) {
                    xAx Q = sources[i]-sources[j];
                    Interval iQ = Q.extrema(rh.pos);
                    if(iQ.contains(0)) {
                        os += stringify(iQ) + "\n";

                        Q.toCurve(rh.pos);
                        vector<Point> crs = Q.crossings(rh.pos);
                        for(unsigned ei = 0; ei < crs.size(); ei++) {
                            draw_cross(cr, crs[ei]);
                        }

                    }
                }
            }
            
            draw_text(cr, rh.pos.midpoint(), 
                      os);
        }
        if(1) {
            xAx oxo=sources[0] - sources[2];
            Timer tm;
            
            tm.ask_for_timeslice();
            tm.start();
                
            std::vector<Point> intrs = intersect(oxo, sources[0] - sources[1]);
            Timer::Time als_time = tm.lap();
            *notify << "intersect time = " << als_time << std::endl;
            for(unsigned i = 0; i < intrs.size(); i++) {
                cairo_save(cr);
                cairo_set_source_rgb(cr, 1, 0,0);
                draw_cross(cr, intrs[i]);
                cairo_stroke(cr);
                cairo_restore(cr);
            }
      
            boost::optional<RatQuad> orq = oxo.toCurve(rh.pos);
            if(orq) {
                RatQuad rq = *orq;
                draw_hull(cr, rq);
                vector<SBasis> hrq = rq.homogenous();
                SBasis vertex_poly = (sources[0] - sources[1]).evaluate_at(hrq[0], hrq[1], hrq[2]);
                //*notify << "\n0: " << hrq[0];
                //*notify << "\n1: " << hrq[1];
                //*notify << "\n2: " << hrq[2];
                vector<double> rts = roots(vertex_poly);
                //*notify << "\nvertex poly:" << vertex_poly << '\n';
                for(unsigned i = 0; i < rts.size(); i++) {
                    draw_circ(cr, Point(rq.pointAt(rts[i])));
                    *notify << "\nrq" << i << ":" << rts[i];
                }

                cairo_save(cr);
                cairo_set_source_rgb(cr, 1, 0, 0);
                RatQuad a, b;
                rq.split(a,b);
                cairo_curve(cr, a.toCubic());
                cairo_curve(cr, b.toCubic());
                cairo_stroke(cr);
                cairo_restore(cr);
            }
        }      
        if(0) {
            RatQuad a, b;
            //rq.split(a,b);
            //cairo_move_to(cr, rq.toCubic().pointAt(0.5));
            cairo_line_to(cr, a.P[2]);
            cairo_stroke(cr);
	
            cairo_curve(cr, a.toCubic());
            cairo_curve(cr, b.toCubic());
      
        }
        cairo_stroke(cr);
	
        //*notify << "w = " << w << "; lambda = " << rq.lambda() << "\n";
        Toy::draw(cr, notify, width, height, save, timer_stream);
    }