int main(){ int n = 6; int m = n; Matrix x = Linspace(-4.0, 4.0, m+1, 1); Matrix y = Linspace(-4.0, 4.0, n+1, 1); Matrix f(x.Size(), y.Size()); for(int i = 0; i < x.Size(); i++){ for(int j = 0; j < y.Size(); j++){ f(i, j) = 1/(1+(x(i)*x(i)) + (y(j)*y(j))); } } Matrix a = Linspace(-4.0, 4.0, 201, 1); a.Write("avals.txt"); Matrix b = Linspace(-4.0, 4.0, 101, 1); b.Write("bvals.txt"); Matrix p6(a.Size(), b.Size()); for(int i = 0; i < a.Size(); i++){ for(int j = 0; j < b.Size(); j++){ p6(i, j) = Lagrange2D(x, y, f, a(i), b(j)); } } p6.Write("p6_uni.txt"); n = 24; m = n; x = Linspace(-4.0, 4.0, m+1, 1); y = Linspace(-4.0, 4.0, n+1, 1); f = Matrix(x.Size(), y.Size()); for(int i = 0; i < x.Size(); i++){ for(int j = 0; j < y.Size(); j++){ f(i, j) = 1/(1+(x(i)*x(i)) + (y(j)*y(j))); } } Matrix p24(a.Size(), b.Size()); for(int i = 0; i < a.Size(); i++){ for(int j = 0; j < b.Size(); j++){ p24(i, j) = Lagrange2D(x, y, f, a(i), b(j)); } } p24.Write("p24_uni.txt"); Matrix runge(201, 101); for(int i = 0; i < a.Size(); i++){ for(int j = 0; j < b.Size(); j++){ runge(i, j) = 1/(1+(a(i)*a(i)) + (b(j)*b(j))); } } //create runge matrix runge.Write("Runge.txt"); }
void addWeighted(WpointVector &list,ConvexDecompInterface *callback) { Wpoint p1(mP1,mC1); Wpoint p2(mP2,mC2); Wpoint p3(mP3,mC3); Vector3d d1 = mNear1 - mP1; Vector3d d2 = mNear2 - mP2; Vector3d d3 = mNear3 - mP3; d1*=WSCALE; d2*=WSCALE; d3*=WSCALE; d1 = d1 + mP1; d2 = d2 + mP2; d3 = d3 + mP3; Wpoint p4(d1,mC1); Wpoint p5(d2,mC2); Wpoint p6(d3,mC3); list.push_back(p1); list.push_back(p2); list.push_back(p3); list.push_back(p4); list.push_back(p5); list.push_back(p6); #if 0 callback->ConvexDebugPoint(mP1.Ptr(),0.01f,0x00FF00); callback->ConvexDebugPoint(mP2.Ptr(),0.01f,0x00FF00); callback->ConvexDebugPoint(mP3.Ptr(),0.01f,0x00FF00); callback->ConvexDebugPoint(d1.Ptr(),0.01f,0xFF0000); callback->ConvexDebugPoint(d2.Ptr(),0.01f,0xFF0000); callback->ConvexDebugPoint(d3.Ptr(),0.01f,0xFF0000); callback->ConvexDebugTri(mP1.Ptr(), d1.Ptr(), d1.Ptr(),0x00FF00); callback->ConvexDebugTri(mP2.Ptr(), d2.Ptr(), d2.Ptr(),0x00FF00); callback->ConvexDebugTri(mP3.Ptr(), d3.Ptr(), d3.Ptr(),0x00FF00); Vector3d np1 = mP1 + mNormal*0.05f; Vector3d np2 = mP2 + mNormal*0.05f; Vector3d np3 = mP3 + mNormal*0.05f; callback->ConvexDebugTri(mP1.Ptr(), np1.Ptr(), np1.Ptr(), 0xFF00FF ); callback->ConvexDebugTri(mP2.Ptr(), np2.Ptr(), np2.Ptr(), 0xFF00FF ); callback->ConvexDebugTri(mP3.Ptr(), np3.Ptr(), np3.Ptr(), 0xFF00FF ); callback->ConvexDebugPoint( np1.Ptr(), 0.01F, 0XFF00FF ); callback->ConvexDebugPoint( np2.Ptr(), 0.01F, 0XFF00FF ); callback->ConvexDebugPoint( np3.Ptr(), 0.01F, 0XFF00FF ); #endif }
int main() { FitParameter p0 (2,0.2,"0p2",0.2,0.2,0.2,0.2); FitParameter p1 (3,0.3,"0p3",0.3,0.3,0.3,0.3); std::cout << "Before" << "\n" << p0 << "\n" << p1 << std::endl; p0.swap(p1); std::cout << "After" << "\n" << p0 << "\n" << p1 << std::endl; Parameter p5 (5,0.5,"0p5",0.5); Parameter p6 (6,0.6,"0p6",0.6); std::cout << "Before" << "\n" << p5 << "\n" << p6 << std::endl; p5.swap(p6); std::cout << "After" << "\n" << p5 << "\n" << p6 << std::endl; std::cout << "////////////////////////" << std::endl; std::cout << "Parameters" << std::endl; Parameters pars0; pars0.AddParameter(p0); pars0.AddParameter(p1); Parameters pars1; pars1.AddParameter(p5); pars1.AddParameter(p6); std::cout << "Before" << "\n" << pars0 << "\n" << pars1 << std::endl; pars0.swap(pars1); std::cout << "After" << "\n" << pars0 << "\n" << pars1 << std::endl; return 0; }
PrimitiveParts cubePrimitive(float width, float height, float depth) { float hx = width / 2; float hy = height / 2; float hz = depth / 2; // create the vertices Point3 p0(hx,hy,hz); Point3 p1(hx,hy,-hz); Point3 p2(-hx,hy,-hz); Point3 p3(-hx,hy,hz); Point3 p4(hx,-hy,hz); Point3 p5(hx,-hy,-hz); Point3 p6(-hx,-hy,-hz); Point3 p7(-hx,-hy,hz); QList<int> f0 = QList<int>() << 0 << 1 << 2 << 3; QList<int> f1 = QList<int>() << 4 << 5 << 1 << 0; QList<int> f2 = QList<int>() << 6 << 2 << 1 << 5; QList<int> f3 = QList<int>() << 7 << 3 << 2 << 6; QList<int> f4 = QList<int>() << 7 << 4 << 0 << 3; QList<int> f5 = QList<int>() << 4 << 7 << 6 << 5; PrimitiveParts parts; parts.points = QVector<Point3>() << p0 << p1 << p2 << p3 << p4 << p5 << p6 << p7; parts.faces = QVector<QList<int> >() << f0 << f1 << f2 << f3 << f4 << f5; return parts; }
void Bezier::split(double t, Bezier & left, Bezier & right) const { // http://processingjs.nihongoresources.com/bezierinfo/sketchsource.php?sketch=CubicDeCasteljau // interpolate from 4 to 3 points QPointF p5((1-t)*m_endpoint0.x() + t*m_cp0.x(), (1-t)*m_endpoint0.y() + t*m_cp0.y()); QPointF p6((1-t)*m_cp0.x() + t*m_cp1.x(), (1-t)*m_cp0.y() + t*m_cp1.y()); QPointF p7((1-t)*m_cp1.x() + t*m_endpoint1.x(), (1-t)*m_cp1.y() + t*m_endpoint1.y()); // interpolate from 3 to 2 points QPointF p8((1-t)*p5.x() + t*p6.x(), (1-t)*p5.y() + t*p6.y()); QPointF p9((1-t)*p6.x() + t*p7.x(), (1-t)*p6.y() + t*p7.y()); // interpolate from 2 points to 1 point QPointF p10((1-t)*p8.x() + t*p9.x(), (1-t)*p8.y() + t*p9.y()); // we now have all the values we need to build the subcurves left.m_endpoint0 = m_endpoint0; left.m_cp0 = p5; left.m_cp1 = p8; right.m_endpoint0 = left.m_endpoint1 = p10; right.m_cp0 = p9; right.m_cp1 = p7; right.m_endpoint1 = m_endpoint1; left.m_isEmpty = right.m_isEmpty = false; }
std::vector<Eigen::Vector2i> PathPlanner::getNeighbours(Eigen::Vector2i p) { Eigen::Vector2i p0(p(0) + 1, p(1)); Eigen::Vector2i p1(p(0) - 1, p(1)); Eigen::Vector2i p2(p(0), p(1) + 1); Eigen::Vector2i p3(p(0), p(1) - 1); Eigen::Vector2i p4(p(0) + 1, p(1) + 1); Eigen::Vector2i p5(p(0) - 1, p(1) - 1); Eigen::Vector2i p6(p(0) - 1, p(1) + 1); Eigen::Vector2i p7(p(0) + 1, p(1) - 1); std::vector<Eigen::Vector2i> points; if(validPoint(p0)) points.push_back(p0); if(validPoint(p1)) points.push_back(p1); if(validPoint(p2)) points.push_back(p2); if(validPoint(p3)) points.push_back(p3); //Disallow walking through diagonal cracks if(validPoint(p4) && (validPoint(p0) || validPoint(p2))) points.push_back(p4); if(validPoint(p5) && (validPoint(p1) || validPoint(p3))) points.push_back(p5); if(validPoint(p6) && (validPoint(p1) || validPoint(p2))) points.push_back(p6); if(validPoint(p7) && (validPoint(p0) || validPoint(p3))) points.push_back(p7); return points; }
int main() { // Construct an arrangement of seven intersecting line segments. Point_2 p1(1, 1), p2(1, 4), p3(2, 2), p4(3, 7), p5(4, 4), p6(7, 1), p7(9, 3); Ex_arrangement arr; insert(arr, Segment_2(p1, p6)); insert(arr, Segment_2(p1, p4)); insert(arr, Segment_2(p2, p6)); insert(arr, Segment_2(p3, p7)); insert(arr, Segment_2(p3, p5)); insert(arr, Segment_2(p6, p7)); insert(arr, Segment_2(p4, p7)); // Create a mapping of the arrangement faces to indices. Face_index_map index_map(arr); // Perform breadth-first search from the unbounded face, using the event // visitor to associate each arrangement face with its discover time. unsigned int time = 0; boost::breadth_first_search(Dual_arrangement(arr), arr.unbounded_face(), boost::vertex_index_map(index_map).visitor (boost::make_bfs_visitor (stamp_times(Face_property_map(), time, boost::on_discover_vertex())))); // Print the discover time of each arrangement face. Ex_arrangement::Face_iterator fit; for (fit = arr.faces_begin(); fit != arr.faces_end(); ++fit) { std::cout << "Discover time " << fit->data() << " for "; if (fit != arr.unbounded_face()) { std::cout << "face "; print_ccb<Ex_arrangement>(fit->outer_ccb()); } else std::cout << "the unbounded face." << std::endl; } return 0; }
void measurement_overhead() { printf("Measurement, 0, 0\n"); PM("","RDTSC, "O_STR); #define FOR_MEAS for (int k = 0; k < 100; ++k) { ; } double m; uint64_t med, se, min, max; measure(FOR_MEAS,m,med,se,min,max,10000); printf("Loop, "O_STR, m/100, med/100, se/100, min/100, max/100); printf("Function Calls, 0, 0\n"); PM_COUNT(p0(), "p0, "O_STR,1000000); PM_COUNT(p1(1), "p1, "O_STR,1000000); PM_COUNT(p2(1,2), "p2, "O_STR,1000000); PM_COUNT(p3(1,2,3), "p3, "O_STR,1000000); PM_COUNT(p4(1,2,3,4), "p4, "O_STR,1000000); PM_COUNT(p5(1,2,3,4,5), "p5, "O_STR,1000000); PM_COUNT(p6(1,2,3,4,5,6), "p6, "O_STR,1000000); PM_COUNT(p7(1,2,3,4,5,6,7), "p7, "O_STR,1000000); }
BDic* find_nodeQueryPacket(char node[20], char target[20]) { BDic* res = neutralPacket(); BString* a3a = new BString ("q"); BString* a3b = new BString ("find_node");; std::pair<BString*, Bencodable *> p3(a3a, a3b); res->push_back(p3); BString* a4a = new BString ("a"); BDic* a4b = new BDic; BString* a5a = new BString ("id"); BString* a5b = new BString (node); std::pair<BString*, Bencodable *> p5(a5a, a5b); a4b->push_back(p5); BString* a6a = new BString ("target"); BString* a6b = new BString (target); std::pair<BString*, Bencodable *> p6(a6a, a6b); a4b->push_back(p6); std::pair<BString*, Bencodable *> p4(a4a, a4b); res->push_back(p4); return res; }
int main() { vec v1(1, 1), v2(0, 2); cout << "vec1(1,1) cross vec2(0,2): " << cross(v1, v2) << endl << endl; node p0(0, 0), p1(0, 1), p2(1, 2), p3(2, 1), p4(2, 0), p5(1, 0), p6(1, 1); node s[7]; s[0] = p4, s[1] = p3, s[2] = p2, s[3] = p1, s[4] = p0, s[5] = p5, s[6] = p6; segment l0(p0, p3), l1(p5, p6), l2(p6, p4), l3(p1, p2); test_segment(l0, l1); test_segment(l1, l2); test_segment(l0, l3); segment ll[4]; ll[0] = l0, ll[1] = l1, ll[2] = l2, ll[3] = l3; for(int i = 0; i < 4; ++ i) { ll[i].s_lt.n_idx = i; ll[i].s_rt.n_idx = i; ll[i].s_lt.n_lt = 1; ll[i].s_rt.n_lt = 0; } cout << "sweeping:" << endl; for(int i = 0; i < 4; ++ i) ll[i].s_print(); if(sweeping(ll, 4)) cout << "yes" << endl; else cout << "no" << endl; return(0); }
void generateTriPrism(GLuint program, ShapeData* triPrismData) { int Index = 0; point3 p1(1.0f, -0.5f, 0.0f); point3 p2(0.0f, -0.5f, 0.0f); point3 p3(0.0f, -0.5f, 1.0f); point3 p4(1.0f, 0.5f, 0.0f); point3 p5(0.0f, 0.5f, 0.0f); point3 p6(0.0f, 0.5f, 1.0f); // Bottom of the triangular prism triPrismPoints[Index] = p1; triPrismNormals[Index] = point3(0.0f, -1.0f, 0.0f); Index++; triPrismPoints[Index] = p3; triPrismNormals[Index] = point3(0.0f, -1.0f, 0.0f); Index++; triPrismPoints[Index] = p2; triPrismNormals[Index] = point3(0.0f, -1.0f, 0.0f); Index++; // Top of the triangular prism triPrismPoints[Index] = p4; triPrismNormals[Index] = point3(0.0f, 1.0f, 0.0f); Index++; triPrismPoints[Index] = p5; triPrismNormals[Index] = point3(0.0f, 1.0f, 0.0f); Index++; triPrismPoints[Index] = p6; triPrismNormals[Index] = point3(0.0f, 1.0f, 0.0f); Index++; // Back of the triangular prism triPrismPoints[Index] = p1; triPrismNormals[Index] = point3(0.0f, 0.0f, -1.0f); Index++; triPrismPoints[Index] = p2; triPrismNormals[Index] = point3(0.0f, 0.0f, -1.0f); Index++; triPrismPoints[Index] = p4; triPrismNormals[Index] = point3(0.0f, 0.0f, -1.0f); Index++; triPrismPoints[Index] = p2; triPrismNormals[Index] = point3(0.0f, 0.0f, -1.0f); Index++; triPrismPoints[Index] = p5; triPrismNormals[Index] = point3(0.0f, 0.0f, -1.0f); Index++; triPrismPoints[Index] = p4; triPrismNormals[Index] = point3(0.0f, 0.0f, -1.0f); Index++; // Left of the triangular prism triPrismPoints[Index] = p2; triPrismNormals[Index] = point3(-1.0f, 0.0f, 0.0f); Index++; triPrismPoints[Index] = p3; triPrismNormals[Index] = point3(-1.0f, 0.0f, 0.0f); Index++; triPrismPoints[Index] = p6; triPrismNormals[Index] = point3(-1.0f, 0.0f, 0.0f); Index++; triPrismPoints[Index] = p2; triPrismNormals[Index] = point3(-1.0f, 0.0f, 0.0f); Index++; triPrismPoints[Index] = p6; triPrismNormals[Index] = point3(-1.0f, 0.0f, 0.0f); Index++; triPrismPoints[Index] = p5; triPrismNormals[Index] = point3(-1.0f, 0.0f, 0.0f); Index++; // Front of the triangular prism triPrismPoints[Index] = p1; triPrismNormals[Index] = point3(1.0f, 0.0f, 1.0f); Index++; triPrismPoints[Index] = p6; triPrismNormals[Index] = point3(1.0f, 0.0f, 1.0f); Index++; triPrismPoints[Index] = p3; triPrismNormals[Index] = point3(1.0f, 0.0f, 1.0f); Index++; triPrismPoints[Index] = p1; triPrismNormals[Index] = point3(1.0f, 0.0f, 1.0f); Index++; triPrismPoints[Index] = p4; triPrismNormals[Index] = point3(1.0f, 0.0f, 1.0f); Index++; triPrismPoints[Index] = p6; triPrismNormals[Index] = point3(1.0f, 0.0f, 1.0f); Index++; triPrismData->numVertices = numTriPrismVertices; glGenVertexArrays( 1, &triPrismData->vao ); glBindVertexArray( triPrismData->vao ); setVertexAttrib(program, (float*)triPrismPoints, sizeof(triPrismPoints), (float*)triPrismNormals, sizeof(triPrismNormals), 0, 0); }
void RectangleSlice::generateOuterWall45(int wall_width) { Eigen::Rotation2D<float> R(0.7854); Eigen::Vector2f p0((LINE_WIDTH * 2 * wall_width), (LINE_WIDTH * 2 * wall_width)); p0 = R * p0; moveToStart45(); _width -= p0(0); _length -= p0(1); for(int i = 0; i < wall_width; i++) { Eigen::Vector2f p1(0.0, _width); Eigen::Vector2f p2(-_length, 0.0); Eigen::Vector2f p3(0.0, -_width); Eigen::Vector2f p4(_length, 0.0); Eigen::Vector2f p5(LINE_WIDTH, -LINE_WIDTH); Eigen::Vector2f p6((LINE_WIDTH * 2), (LINE_WIDTH * 2)); p1 = R * p1; p2 = R * p2; p3 = R * p3; p4 = R * p4; p5 = R * p5; p6 = R * p6; _ph->extrudeAlongXYAxis(p1(0), p1(1)); _ph->extrudeAlongXYAxis(p2(0), p2(1)); _ph->extrudeAlongXYAxis(p3(0), p3(1)); _ph->extrudeAlongXYAxis(p4(0), p4(1)); _ph->moveAlongXYAxis(p5(0), p5(1)); _width += p6(0); _length += p6(0); } _ph->moveZAxis(); }
int main() { try { symbol k("k"),q("q"),p("p"),p1("p1"),p2("p2"),p3("p3"),ms("ms"),l("l"),s("s"),m1s("m1s"),m2s("m2s"),m3s("m3s"); symbol l1("l1"),l2("l2"),l3("l3"),l4("l4"),t("t"),p4("p4"),p5("p5"),p6("p6"),tp("tp"),v1("v1"),v2("v2"),l5("l5"); symbol k1("k1"),k2("k2"),k3("k3"),k4("k4"),k5("k5"),ms1("ms1"),ms2("ms2"),ms3("ms3"),ms4("ms4"); symbol s12("s12"),s23("s23"),s34("s34"),s45("s45"),s51("s51"),s13("s13"),s15("s15"),s56("s56"),s16("s16"),s123("s123"),s234("s234"),s345("s345"); lst inv_l; inv_l.append(p1*p1 == 0); inv_l.append( p2*p2 == 0);inv_l.append( p3*p3 == 0);inv_l.append( p4*p4 == 0);inv_l.append( p5*p5 == 0);inv_l.append( p6*p6 == 0); inv_l.append(p1* p2 == s12/2);inv_l.append( p2* p3 == s23/2);inv_l.append( p3* p4 == s34/2);inv_l.append( p4* p5 == s45/2); inv_l.append(p5* p6 == s56/2);inv_l.append( p1* p6 == s16/2);inv_l.append( p1* p3 == (-s12 + s123 - s23)/2); inv_l.append(p2* p4 == (-s23 + s234 - s34)/2); inv_l.append( p3* p5 == (-s34 + s345 - s45)/2); inv_l.append(p1* p4 == (-s123 + s23 - s234 + s56)/2); inv_l.append(p1* p5 == (-s16 + s234 - s56)/2); inv_l.append( p2* p5 == (s16 - s234 + s34 - s345)/2); inv_l.append( p2* p6 == (-s12 - s16 + s345)/2); inv_l.append( p3* p6 == (s12 - s123 - s345 + s45)/2); inv_l.append( p4* p6 == (s123 - s45 - s56)/2); RoMB_loop_by_loop hexag(lst(k1), lst(-pow(p1 + k1,2),-pow(p1 + p2 + k1,2), -pow(p1 + p2 + p3 + k1,2), -pow(p1 + p2 + p3 + p4 + k1,2), -pow(p1+p2+p3+p4+p5+k1,2),-pow(k1,2)), inv_l, lst(1,1,1,1,1,1),true); hexag.integrate_map(lst(s12 == -1, s23 == -2, s34 == -3, s45 == -4, s56 == -5, s16 == -6, s123 == -7, s234 == -8, s345 == -9)); /* FRESULT for parameters: {s12==-1,s23==-2,s34==-3,s45==-4,s56==-5,s16==-6,s123==-7,s234==-8,s345==-9} FRESULT anl : = -0.1955084880526298663-1/240*log(8)*log(6)+947/60480*log(2)^2-1/480*log(6)*log(4)+1/1080*log(3)*log(7)+131/7560*log(9)*log(2)+19/1260*log(9)^2-1/560*log(8)*log(4)+523/60480*log(3)^2-1/1080*log(7)*log(5)+41/4320*log(3)*log(5)-1/48*log(8)*log(5)-1/1080*log(7)*log(4)+22/945*log(6)*log(7)+19/3780*log(3)*log(4)+493/30240*Pi^2+43/1008*eps^(-2)+49/8640*log(5)^2-641/30240*log(2)*log(6)+1/1080*log(9)*log(5)-22/945*log(2)*log(7)+271/60480*log(4)^2-3/112*log(8)*log(3)-19/3780*log(9)*log(4)+1/1080*log(4)*log(5)-61/2520*log(9)*log(7)+61/5040*log(7)^2+1/168*log(3)*log(2)+1/168*log(8)*log(9)+13/3360*log(2)*log(4)-1/30240*(-1132.7960047725738361+576*log(8)-163*log(3)+264*log(9)+533*log(2)-479*log(6)-444*log(7)+271*log(4)-287*log(5))*eps^(-1)+47/1680*log(8)^2-17/1680*log(8)*log(2)+767/60480*log(6)^2-22/945*log(9)*log(6)-13/1890*log(3)*log(9) FRESULT num: = 1.9907333428263254975E-4+(0.032177795803854872908)*eps^(-1)+(0.04265873015873015873)*eps^(-2) eps^-2 term: 43/1008 +/- 0 eps^-1 term: 0.03746018534300839405-2/105*log(8)+163/30240*log(3)-11/1260*log(9)-533/30240*log(2)+479/30240*log(6)+37/2520*log(7)-271/30240*log(4)+41/4320*log(5) +/- 9.022403780167233619E-6 eps^0 term: -0.1955084880526298663-1/240*log(8)*log(6)+947/60480*log(2)^2-1/480*log(6)*log(4)+1/1080*log(3)*log(7)+131/7560*log(9)*log(2)+19/1260*log(9)^2-1/560*log(8)*log(4)+523/60480*log(3)^2-1/1080*log(7)*log(5)+41/4320*log(3)*log(5)-1/48*log(8)*log(5)-1/1080*log(7)*log(4)+22/945*log(6)*log(7)+19/3780*log(3)*log(4)+493/30240*Pi^2+49/8640*log(5)^2-641/30240*log(2)*log(6)+1/1080*log(9)*log(5)-22/945*log(2)*log(7)+271/60480*log(4)^2-3/112*log(8)*log(3)-19/3780*log(9)*log(4)+1/1080*log(4)*log(5)-61/2520*log(9)*log(7)+61/5040*log(7)^2+1/168*log(3)*log(2)+1/168*log(8)*log(9)+13/3360*log(2)*log(4)+47/1680*log(8)^2-17/1680*log(8)*log(2)+767/60480*log(6)^2-22/945*log(9)*log(6)-13/1890*log(3)*log(9) +/- 1.04620404922048185285E-4 */ } catch(std::exception &p) { std::cerr<<"******************************************************************"<<endl; std::cerr<<" >>>ERROR: "<<p.what()<<endl; std::cerr<<"******************************************************************"<<endl; return 1; } return 0; }
void KisNodeDelegate::drawFrame(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const { KisNodeViewColorScheme scm; QPen oldPen = p->pen(); p->setPen(scm.gridColor(option, d->view)); const QPoint base = option.rect.topLeft(); QPoint p2 = base + QPoint(-scm.indentation() - 1, 0); QPoint p3 = base + QPoint(-2 * scm.border() - 2 * scm.decorationMargin() - scm.decorationSize(), 0); QPoint p4 = base + QPoint(-1, 0); QPoint p5(iconsRect(option, index).left() - 1, base.y()); QPoint p6(option.rect.right(), base.y()); QPoint v(0, option.rect.height()); const bool paintForParent = index.parent().isValid() && !index.row(); if (paintForParent) { QPoint p1(-2 * scm.indentation() - 1, 0); p1 += base; p->drawLine(p1, p2); } QPoint k0(0, base.y()); QPoint k1(1 * scm.border() + 2 * scm.visibilityMargin() + scm.visibilitySize(), base.y()); p->drawLine(k0, k1); p->drawLine(k0 + v, k1 + v); p->drawLine(k0, k0 + v); p->drawLine(k1, k1 + v); p->drawLine(p2, p6); p->drawLine(p2 + v, p6 + v); p->drawLine(p2, p2 + v); p->drawLine(p3, p3 + v); p->drawLine(p4, p4 + v); p->drawLine(p5, p5 + v); p->drawLine(p6, p6 + v); //// For debugging purposes only //p->setPen(Qt::blue); //KritaUtils::renderExactRect(p, iconsRect(option, index)); //KritaUtils::renderExactRect(p, textRect(option, index)); //KritaUtils::renderExactRect(p, scm.relThumbnailRect().translated(option.rect.topLeft())); p->setPen(oldPen); }
void BBox::render() { Vec3d p0(inf), p1(sup[0], inf[1], inf[2]), p2(sup[0], sup[1], inf[2]), p3(inf[0], sup[1], inf[2]), p4(inf[0], inf[1], sup[2]), p5(sup[0], inf[1], sup[2]), p6(sup), p7(inf[0], sup[1], sup[2]); glBegin(GL_LINES); glVertex3dv(&p0[0]); glVertex3dv(&p1[0]); glVertex3dv(&p1[0]); glVertex3dv(&p2[0]); glVertex3dv(&p2[0]); glVertex3dv(&p3[0]); glVertex3dv(&p3[0]); glVertex3dv(&p0[0]); glVertex3dv(&p4[0]); glVertex3dv(&p5[0]); glVertex3dv(&p5[0]); glVertex3dv(&p6[0]); glVertex3dv(&p6[0]); glVertex3dv(&p7[0]); glVertex3dv(&p7[0]); glVertex3dv(&p4[0]); glVertex3dv(&p0[0]); glVertex3dv(&p4[0]); glVertex3dv(&p1[0]); glVertex3dv(&p5[0]); glVertex3dv(&p2[0]); glVertex3dv(&p6[0]); glVertex3dv(&p3[0]); glVertex3dv(&p7[0]); glEnd(); }
void ExplosionSystem::addExplosion(glm::vec3 origin) { MistEffect *g_MistEffect = new MistEffect(150); MistEmitter *g_MistEmitter = new MistEmitter(); BurstEffect *g_BurstEffect = new BurstEffect(40); BurstEmitter *g_BurstEmitter = new BurstEmitter(); ShockwaveEffect *g_ShockwaveEffect = new ShockwaveEffect(1); ShockwaveEmitter *g_ShockwaveEmitter = new ShockwaveEmitter(); FlashEffect *g_FlashEffect = new FlashEffect(5); FlashEmitter *g_FlashEmitter = new FlashEmitter(); ExplosionSparksEffect *g_ExplosionSparksEffect = new ExplosionSparksEffect(40); ExplosionSparksEmitter *g_ExplosionSparksEmitter = new ExplosionSparksEmitter(); DebrisEffect *g_DebrisEffect = new DebrisEffect(25); DebrisEmitter *g_DebrisEmitter = new DebrisEmitter(); TrailSystem *g_TrailSystem = new TrailSystem(15, origin); g_MistEmitter->setOrigin(origin); g_BurstEmitter->setOrigin(origin); g_ShockwaveEmitter->setOrigin(origin); g_FlashEmitter->setOrigin(origin); g_ExplosionSparksEmitter->setOrigin(origin); g_DebrisEmitter->setOrigin(origin); std::pair <MistEffect, MistEmitter> p1 (*g_MistEffect, *g_MistEmitter); std::pair <BurstEffect, BurstEmitter> p2 (*g_BurstEffect, *g_BurstEmitter); std::pair <ShockwaveEffect, ShockwaveEmitter> p3 (*g_ShockwaveEffect, *g_ShockwaveEmitter); std::pair <FlashEffect, FlashEmitter> p4 (*g_FlashEffect, *g_FlashEmitter); std::pair <ExplosionSparksEffect, ExplosionSparksEmitter> p5 (*g_ExplosionSparksEffect, *g_ExplosionSparksEmitter); std::pair <DebrisEffect, DebrisEmitter> p6 (*g_DebrisEffect, *g_DebrisEmitter); MistVector.push_back(p1); BurstVector.push_back(p2); ShockwaveVector.push_back(p3); FlashVector.push_back(p4); SparksVector.push_back(p5); DebrisVector.push_back(p6); g_TrailSystem->setCamera(camera); g_TrailSystem->addTrails(); TrailSystemVector.push_back(*g_TrailSystem); }
void init_crown_mesh(GLShape& mesh) { float x0 = 0.1f; float y0 = 0.025f; float y1 = 0.05f; float x1 = 0.5f * x0; Vector2 p0(-x0, 0.0f); Vector2 p1(x0, 0.0f); Vector2 p2(x0, y1); Vector2 p3(x1, y0); Vector2 p4(0.0f, y1); Vector2 p5(-x1, y0); Vector2 p6(-x0, y1); mesh = to_xy(triangulate({p0, p1, p2, p3, p4, p5, p6})); }
void PE_IO::fire_PI() { token_type x0,x1,x2,x3,x4,x5,x6,x7; x0.re=(rand()%10000)/10000.0000; x0.im=(rand()%10000)/10000.0000; x1.re=(rand()%10000)/10000.0000; x1.im=(rand()%10000)/10000.0000; x2.re=(rand()%10000)/10000.0000; x2.im=(rand()%10000)/10000.0000; x3.re=(rand()%10000)/10000.0000; x3.im=(rand()%10000)/10000.0000; x4.re=(rand()%10000)/10000.0000; x4.im=(rand()%10000)/10000.0000; x5.re=(rand()%10000)/10000.0000; x5.im=(rand()%10000)/10000.0000; x6.re=(rand()%10000)/10000.0000; x6.im=(rand()%10000)/10000.0000; x7.re=(rand()%10000)/10000.0000; x7.im=(rand()%10000)/10000.0000; packet p0(x_, y_, 1, 0, x0); printf("Round %d:PI: send x0 %.4f+%.4fi to (%d,%d)\n", pifire,x0.re,x0.im, p0.dest_x, p0.dest_y); packet p1(x_, y_, 1, 2, x1); printf("Round %d:PI: send x1 %.4f+%.4fi to (%d,%d)\n", pifire,x1.re,x1.im, p1.dest_x, p1.dest_y); packet p2(x_, y_, 2, 1, x2); printf("Round %d:PI: send x2 %.4f+%.4fi to (%d,%d)\n", pifire,x2.re,x2.im, p2.dest_x, p2.dest_y); packet p3(x_, y_, 0, 1, x3); printf("Round %d:PI: send x3 %.4f+%.4fi to (%d,%d)\n", pifire,x3.re,x3.im, p3.dest_x, p3.dest_y); packet p4(x_, y_, 1, 0, x4); printf("Round %d:PI: send x4 %.4f+%.4fi to (%d,%d)\n", pifire,x4.re,x4.im, p4.dest_x, p4.dest_y); packet p5(x_, y_, 1, 2, x5); printf("Round %d:PI: send x5 %.4f+%.4fi to (%d,%d)\n", pifire,x5.re,x5.im, p5.dest_x, p5.dest_y); packet p6(x_, y_, 2, 1, x6); printf("Round %d:PI: send x6 %.4f+%.4fi to (%d,%d)\n", pifire,x6.re,x6.im, p6.dest_x, p6.dest_y); packet p7(x_, y_, 0, 1, x7); printf("Round %d:PI: send x7 %.4f+%.4fi to (%d,%d)\n", pifire,x7.re,x7.im, p7.dest_x, p7.dest_y); out_queue_.push_back(p0); out_queue_.push_back(p1); out_queue_.push_back(p2); out_queue_.push_back(p3); out_queue_.push_back(p4); out_queue_.push_back(p5); out_queue_.push_back(p6); out_queue_.push_back(p7); pifire++; }
void COGLCubeMap::LoadCubeMapFromPath(const std::string& path) { std::string p1(path); std::string p2(path); std::string p3(path); std::string p4(path); std::string p5(path); std::string p6(path); LoadCubeMapFromFiles( p1.append("pos_x.png").c_str(), p2.append("neg_x.png").c_str(), p3.append("pos_y.png").c_str(), p4.append("neg_y.png").c_str(), p5.append("pos_z.png").c_str(), p6.append("neg_z.png").c_str()); }
void CTest::x_TestErrCode() { NcbiCout << "Testing ErrCodes\n"; CNcbiDiag p1( CDiagCompileInfo("", 0, NCBI_CURRENT_FUNCTION) ); p1.SetErrorCode(-6,-10); m_Diags.push_back(&p1); CNcbiDiag p2( CDiagCompileInfo("", 0, NCBI_CURRENT_FUNCTION) ); p2.SetErrorCode(-6,10); m_Diags.push_back(&p2); CNcbiDiag p3( CDiagCompileInfo("", 0, NCBI_CURRENT_FUNCTION) ); p3.SetErrorCode(20,1); m_Diags.push_back(&p3); CNcbiDiag p4( CDiagCompileInfo("", 0, NCBI_CURRENT_FUNCTION) ); p4.SetErrorCode(21,1); m_Diags.push_back(&p4); CNcbiDiag p5( CDiagCompileInfo("", 0, NCBI_CURRENT_FUNCTION) ); p5.SetErrorCode(31,21); m_Diags.push_back(&p5); CNcbiDiag p6( CDiagCompileInfo("", 0, NCBI_CURRENT_FUNCTION) ); p6.SetErrorCode(40,1); m_Diags.push_back(&p6); { int expects[] = { 1, 1, 1, 0, 0, 1 }; x_TestString("(-10--5,20,30-40.) !(31.1-100)",expects); } { int expects[] = { 1, 0, 0, 1, 1, 0 }; x_TestString("!(-10--5,20,30-40.1-20)",expects); } { int expects[] = { 1, 0, 0, 1, 1, 0 }; x_TestString("!(20.) !(30-40.1-20) !(-6.1-100)",expects); } m_Diags.clear(); }
TEST( Orient_Exact3, Test1 ) { GeoLib::Point_3 p1(0,0,0), p2(1,0,0), p3(0,1,0), p4(0,0,1), p5(0,0,-1), p6(2,2,0); double dRight = GeoLib::OrientExact_3( p1, p2, p3, p4 ); EXPECT_TRUE( dRight < 0 ); double dLeft = GeoLib::OrientExact_3( p1, p2, p3, p5 ); EXPECT_TRUE( dLeft > 0 ); double dZero = GeoLib::OrientExact_3( p1, p2, p3, p6 ); EXPECT_NEAR( 0.0, dZero, 1E-30 ); double dInvRight = GeoLib::OrientExact_3( p1, p2, p4, p3 ); // swap p3, p4 EXPECT_TRUE( dInvRight > 0 ); double dInvLeft = GeoLib::OrientExact_3( p1, p2, p5, p3 ); // swap p3, p5 EXPECT_TRUE( dInvLeft < 0 ); }
int main(int argc, char* argv[]) { chain<ReqGenerator, ReqParser, ReqPrinter> p2; p2(); chain<ReqGenerator, ReqParser2, ReqPrinter> p3; p3(); chain<ReqGenerator, ReqParser, ReqParser2, ReqPrinter> p4; p4(); chain<ReqGenerator, ReqParser, ReqPrinter2> p5; p5(); chain<ReqGenerator, ReqParser2, ReqPrinter2> p6; p6(); chain<ReqGenerator, ReqParser3, ReqPrinter2, ReqPrinter3> p7; p7(); }
/** * Load a predefined set of double-click gestures patterns. * Theses patterns are manualy recorded @ 20FPS * If the framerate changes the patterns wont be relevant anymore. */ void DoubleClickFilter::loadDoubleClickPatterns() { cv::Mat p1( sizeof(doubleClickPattern_1)/sizeof(float), 1, CV_32F, doubleClickPattern_1 ); cv::Mat p2( sizeof(doubleClickPattern_2)/sizeof(float), 1, CV_32F, doubleClickPattern_2 ); cv::Mat p3( sizeof(doubleClickPattern_3)/sizeof(float), 1, CV_32F, doubleClickPattern_3 ); cv::Mat p4( sizeof(doubleClickPattern_4)/sizeof(float), 1, CV_32F, doubleClickPattern_4 ); cv::Mat p5( sizeof(doubleClickPattern_5)/sizeof(float), 1, CV_32F, doubleClickPattern_5 ); cv::Mat p6( sizeof(doubleClickPattern_6)/sizeof(float), 1, CV_32F, doubleClickPattern_6 ); cv::Mat p7( sizeof(doubleClickPattern_7)/sizeof(float), 1, CV_32F, doubleClickPattern_7 ); cv::Mat p8( sizeof(doubleClickPattern_8)/sizeof(float), 1, CV_32F, doubleClickPattern_8 ); addPattern( p1 ); addPattern( p2 ); addPattern( p3 ); addPattern( p4 ); addPattern( p5 ); addPattern( p6 ); addPattern( p7 ); addPattern( p8 ); }
int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; Player p1("Emma", 4); Player p2("Emma", 4); Player p3("Emma", 4); Player p4("Emma", 4); Player p5("Emma", 4); Player p6("Emma", 4); Player p7("Emma", 4); Player p8("Emma", 4); Player p9("Emma", 4); Player p10("Emma", 4); Player p11("Emma", 4); Player p12("Emma", 4); Match m(3); engine.rootContext()->setContextProperty("player1", &p1); engine.rootContext()->setContextProperty("player2", &p2); engine.rootContext()->setContextProperty("player3", &p3); engine.rootContext()->setContextProperty("player4", &p4); engine.rootContext()->setContextProperty("player5", &p5); engine.rootContext()->setContextProperty("player6", &p6); engine.rootContext()->setContextProperty("player7", &p7); engine.rootContext()->setContextProperty("player8", &p8); engine.rootContext()->setContextProperty("player9", &p9); engine.rootContext()->setContextProperty("player10", &p10); engine.rootContext()->setContextProperty("player11", &p11); engine.rootContext()->setContextProperty("player12", &p12); engine.rootContext()->setContextProperty("match", &m); QCoreApplication::setApplicationName("Lab2"); QCoreApplication::setOrganizationName("EMMA"); QCoreApplication::setOrganizationDomain(".fourThompson"); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
int main() { std::pair<int, float> p1; std::cout << "Value-initialized: " << p1.first << ", " << p1.second << '\n'; std::pair<int, double> p2(42, 0.123); std::cout << "Initialized with two values: " << p2.first << ", " << p2.second << '\n'; std::pair<char, int> p4(p2); std::cout << "Implicitly converted: " << p4.first << ", " << p4.second << '\n'; std::pair<std::complex<double>, std::string> p6( std::piecewise_construct, std::forward_as_tuple(0.123, 7.7), std::forward_as_tuple(10, 'a')); std::cout << "Piecewise constructed: " << p6.first << ", " << p6.second << '\n'; }
void VglPlus::parallelMove(const vgl_line_segment_2d<double> & initSeg, double distance, vgl_line_segment_2d<double> & seg1, vgl_line_segment_2d<double> & seg2) { // CCW rotated vgl_vector_2d<double> orthDir = rotated(initSeg.direction(), vnl_math::pi/2.0); orthDir = normalize(orthDir); vgl_point_2d<double> p1 = initSeg.point1(); vgl_point_2d<double> p2 = initSeg.point2(); vgl_vector_2d<double> dp = distance * orthDir; vgl_point_2d<double> p3(p1.x() + dp.x(), p1.y() + dp.y()); vgl_point_2d<double> p4(p2.x() + dp.x(), p2.y() + dp.y()); seg1 = vgl_line_segment_2d<double>(p3, p4); dp = -1.0 * dp; vgl_point_2d<double> p5(p1.x() + dp.x(), p1.y() + dp.y()); vgl_point_2d<double> p6(p2.x() + dp.x(), p2.y() + dp.y()); seg2 = vgl_line_segment_2d<double>(p5, p6); }
std::vector<Triangle> triangulationCube(int rayon){ std::vector<Triangle> listeTriangle; Point p0(-rayon, rayon, - rayon); //en haut à gauche Point p1(rayon, rayon, - rayon); //en haut à droite Point p2(rayon, - rayon, - rayon); //en bas à droite Point p3(- rayon, - rayon, - rayon); //en bas à gauche Point p4( - rayon, rayon, rayon); Point p5( rayon, rayon, rayon); Point p6( rayon, - rayon, rayon); Point p7( - rayon, - rayon, rayon); listeTriangle.push_back(Triangle(p0,p1,p2)); listeTriangle.push_back(Triangle(p0,p2,p3)); /* listeTriangle.push_back(Triangle(p4,p5,p6)); listeTriangle.push_back(Triangle(p4,p6,p7)); listeTriangle.push_back(Triangle(p0,p4,p5)); listeTriangle.push_back(Triangle(p0,p5,p1)); listeTriangle.push_back(Triangle(p1,p5,p6)); listeTriangle.push_back(Triangle(p1,p6,p2)); listeTriangle.push_back(Triangle(p6,p2,p3)); listeTriangle.push_back(Triangle(p6,p3,p7)); listeTriangle.push_back(Triangle(p0,p4,p7)); listeTriangle.push_back(Triangle(p0,p7,p3)); */ return listeTriangle; }
void setup(MeshType & mesh, viennagrid::hexahedron_tag) { typedef typename viennagrid::result_of::point<MeshType>::type PointType; typedef typename viennagrid::result_of::vertex_handle<MeshType>::type VertexHandleType; PointType p0(0.0, 0.0, 0.0); PointType p1(1.0, 0.0, 0.0); PointType p2(1.0, 1.0, 0.0); PointType p3(0.0, 1.0, 0.0); PointType p4(0.0, 0.0, 1.0); PointType p5(1.0, 0.0, 1.0); PointType p6(1.0, 1.0, 1.0); PointType p7(0.0, 1.0, 1.0); PointType p8(2.0, 0.0, 0.0); PointType p9(2.0, 1.0, 0.0); PointType p10(2.0, 0.0, 1.0); PointType p11(2.0, 1.0, 1.0); std::cout << "Adding vertices to segment:" << std::endl; VertexHandleType vh0 = viennagrid::make_vertex( mesh, p0 ); VertexHandleType vh1 = viennagrid::make_vertex( mesh, p1 ); VertexHandleType vh2 = viennagrid::make_vertex( mesh, p2 ); VertexHandleType vh3 = viennagrid::make_vertex( mesh, p3 ); VertexHandleType vh4 = viennagrid::make_vertex( mesh, p4 ); VertexHandleType vh5 = viennagrid::make_vertex( mesh, p5 ); VertexHandleType vh6 = viennagrid::make_vertex( mesh, p6 ); VertexHandleType vh7 = viennagrid::make_vertex( mesh, p7 ); VertexHandleType vh8 = viennagrid::make_vertex( mesh, p8 ); VertexHandleType vh9 = viennagrid::make_vertex( mesh, p9 ); VertexHandleType vh10 = viennagrid::make_vertex( mesh, p10 ); VertexHandleType vh11 = viennagrid::make_vertex( mesh, p11 ); viennagrid::make_hexahedron( mesh, vh0, vh1, vh3, vh2, vh4, vh5, vh7, vh6 ); viennagrid::make_hexahedron( mesh, vh1, vh8, vh2, vh9, vh5, vh10, vh6, vh11 ); }
void GfxMesh::addCube(float _size, Vec3f _pos, Vec4f _color, bool _front, bool _back, bool _right, bool _left, bool _top, bool _bottom) { _size /= 2.0f; Vec3f p0(_pos.x - _size, _pos.y - _size, _pos.z + _size); Vec3f p1(_pos.x + _size, _pos.y - _size, _pos.z + _size); Vec3f p2(_pos.x + _size, _pos.y + _size, _pos.z + _size); Vec3f p3(_pos.x - _size, _pos.y + _size, _pos.z + _size); Vec3f p4(_pos.x + _size, _pos.y - _size, _pos.z - _size); Vec3f p5(_pos.x - _size, _pos.y - _size, _pos.z - _size); Vec3f p6(_pos.x - _size, _pos.y + _size, _pos.z - _size); Vec3f p7(_pos.x + _size, _pos.y + _size, _pos.z - _size); Vec3f n; unsigned int v0, v1, v2, v3, v4, v5, v6, v7; // Front if (_front) { n = Vec3f(0.0f, 0.0f, 1.0f); v0 = addVertex(p0, n, _color); v1 = addVertex(p1, n, _color); v2 = addVertex(p2, n, _color); v3 = addVertex(p3, n, _color); addTriangle(v0, v1, v2); addTriangle(v0, v2, v3); } // Back if (_back) { n = Vec3f(0.0f, 0.0f, -1.0f); v4 = addVertex(p4, n, _color); v5 = addVertex(p5, n, _color); v6 = addVertex(p6, n, _color); v7 = addVertex(p7, n, _color); addTriangle(v4, v5, v6); addTriangle(v4, v6, v7); } // Right if (_right) { n = Vec3f(1.0f, 0.0f, 0.0f); v1 = addVertex(p1, n, _color); v4 = addVertex(p4, n, _color); v7 = addVertex(p7, n, _color); v2 = addVertex(p2, n, _color); addTriangle(v1, v4, v7); addTriangle(v1, v7, v2); } // Left if (_left) { n = Vec3f(-1.0f, 0.0f, 0.0f); v5 = addVertex(p5, n, _color); v0 = addVertex(p0, n, _color); v3 = addVertex(p3, n, _color); v6 = addVertex(p6, n, _color); addTriangle(v5, v0, v3); addTriangle(v5, v3, v6); } // Top if (_top) { n = Vec3f(0.0f, 1.0f, 0.0f); v3 = addVertex(p3, n, _color); v2 = addVertex(p2, n, _color); v7 = addVertex(p7, n, _color); v6 = addVertex(p6, n, _color); addTriangle(v3, v2, v7); addTriangle(v3, v7, v6); } // Bottom if (_bottom) { n = Vec3f(0.0f, -1.0f, 0.0f); v5 = addVertex(p5, n, _color); v4 = addVertex(p4, n, _color); v1 = addVertex(p1, n, _color); v0 = addVertex(p0, n, _color); addTriangle(v5, v4, v1); addTriangle(v5, v1, v0); } }
bool UniformGrid::intersectsCell(const Model& model, const CellCoord& coord) { // Left side // Bottom left point Point3D p0 = pointAt(coord); Point3D p1(p0[0], p0[1] + cellSize, p0[2]); Point3D p2(p0[0], p0[1] + cellSize, p0[2] + cellSize); Point3D p3(p0[0], p0[1], p0[2] + cellSize); // Right side Point3D p4(p0[0] + cellSize, p0[1], p0[2]); Point3D p5(p0[0] + cellSize, p0[1] + cellSize, p0[2]); Point3D p6(p0[0] + cellSize, p0[1] + cellSize, p0[2] + cellSize); Point3D p7(p0[0] + cellSize, p0[1], p0[2] + cellSize); const std::vector<Point3D> pts = {p0, p1, p2, p3, p4, p5, p6, p7}; auto cellMat = translationMatrix(p0[0], p0[1], p0[2]) * cellSizeScaleMatrix; // But we need the inverse of course cellMat = cellMat.invert(); // Check if a pt is in the cell auto inCell = [&] (const Point3D& pt) -> bool { return p0[0] <= pt[0] && pt[0] <= (p0[0] + cellSize) && p0[1] <= pt[1] && pt[1] <= (p0[1] + cellSize) && p0[2] <= pt[2] && pt[2] <= (p0[2] + cellSize); }; // First, we need to get the 8 points of the bounding box auto bbox = model.getBoundingBox(); auto inBoundingBox = [&bbox] (const Point3D& pt) -> bool { // We are in the box if we are in between all the opposite parallel planes const auto c1 = bbox[0]; // Bottom back left corner const auto v1a = bbox[1] - c1; // Bottom back left to bottom back right const auto v1b = bbox[3] - c1; // Bottom back left to top back left const auto v1c = bbox[4] - c1; // Bottom back left to bottom front left const auto n1 = v1a.cross(v1b); // Back face const auto n2 = v1b.cross(v1c); // Left face const auto n3 = v1c.cross(v1a); // Bottom face const auto c2 = bbox[6]; // Top front right corner const auto v2a = bbox[5] - c2; // Top front right to bottom front right const auto v2b = bbox[7] - c2; // Top front right to top front left const auto v2c = bbox[2] - c2; // Top front right to top back right // We want this to be opposite sign (i.e. not pointing inwards) // so we do the opposite cross as above const auto n4 = v2b.cross(v2a); // Front face const auto n5 = v2c.cross(v2b); // Top face const auto n6 = v2a.cross(v2c); // Right face return betweenPlanes(n1, c1, n4, c2, pt) && betweenPlanes(n2, c1, n6, c2, pt) && betweenPlanes(n3, c1, n5, c2, pt); }; // A corner of the bbox being inside the cell implies an intersection // between the bbox and the cell. for (const auto& pt : bbox) { if (inCell(pt)) { return true; } } // Similarly, a corner of cell inside bbox implies intersection for (const auto& pt : pts) { if (inBoundingBox(pt)) { return true; } } // Check if any of the 12 lines from bbox intersect this cell HitRecord hr; for (size_t i = 0; i < 8; ++i) { // This is the vector of one edge Vector3D v = bbox[(i % 4 == 0) ? i + 3 : i - 1] - bbox[i]; Ray ray(bbox[i] - v, bbox[i]); if (utilityCube.intersects(ray, &hr, cellMat) && 1 <= hr.t && hr.t <= 2) { // This edge of the bounding box intersects our cell cube. return true; } } for (size_t i = 0; i < 4; ++i) { Vector3D v = bbox[i + 4] - bbox[i]; Ray ray(bbox[i] - v, bbox[i]); if (utilityCube.intersects(ray, &hr, cellMat) && 1 <= hr.t && hr.t <= 2) { // This edge of the bounding box intersects our cell cube. return true; } } // Now check if any of the 12 lines from this cell intersect the model for (size_t i = 0; i < pts.size(); ++i) { Vector3D v = pts[(i % 4 == 0) ? i + 3 : i - 1] - pts[i]; // Note: We are doing pts[i] - v and checking for t between 1 and 2. // This is equivalent to checking between 0 and 1 without doing the // subtraction, *but* we have an epsilon check in the intersects code. // For this case, we do *not* want to bother with epsilon check, so we // will check from 1 to 2 to avoid it. if (model.intersects(Ray(pts[i] - v, pts[i]), &hr)) { if (1 <= hr.t && hr.t <= 2) { return true; } } } // Now we have to check the struts between the two sides for (size_t i = 0; i < 4; ++i) { Vector3D v = pts[i + 4] - pts[i]; if (model.intersects(Ray(pts[i] - v, pts[i]), &hr)) { if (1 <= hr.t && hr.t <= 2) { return true; } } } return false; }