double Cara::getAnguloMax(Malla *malla) { assert(malla != 0); //obtenemos los indices de los arcos de la cara Vect normal_cara = this->getNormal(malla); Punto p1, p2, p3; Vect v1, v2, prod_cruz; double angulo; double angulo_max = 0; for(int i=0; i<num_elem; i++) { p1 = malla->getNodo(ind_nodos[i])->getPunto(); p2 = malla->getNodo(ind_nodos[int(fmod(i+1,num_elem))])->getPunto(); p3 = malla->getNodo(ind_nodos[int(fmod(i+2,num_elem))])->getPunto(); Vect vp1(p1); Vect vp2(p2); Vect vp3(p3); v1 = vp1 - vp2; v2 = vp3 - vp2; prod_cruz = v1.prodCruz(v2); angulo = v1.getAngulo(v2); if(normal_cara.prodPunto(prod_cruz) > 0) { angulo = 2*PI - angulo; } if(angulo > angulo_max) { angulo_max = angulo; } } return angulo_max; }
Vect Cara::getNormal(Malla *malla) { assert(malla != 0); Punto p1,p2,p3; p1 = malla->getNodo(ind_nodos[0])->getPunto(); p2 = malla->getNodo(ind_nodos[1])->getPunto(); p3 = malla->getNodo(ind_nodos[2])->getPunto(); Vect vp1(p1); Vect vp2(p2); Vect vp3(p3); Vect v12 = vp2 - vp1; Vect v13 = vp3 - vp2; Vect N = v12.prodCruz(v13); N.normalizar(); return N; }
double Cara::getAnguloVertice(int ind_nodo, Malla *malla) { assert(malla != 0 && ind_nodo >= 0 && ind_nodo <= malla->getMaxIndiceNodos()); Punto p1, p2, p3; Vect v1, v2; double angulo; for(int i=0; i<(int)ind_nodos.size(); i++) { // Buscamos que el nodo ind_nodo esté al medio if(ind_nodo != ind_nodos[int(fmod(i+1,ind_nodos.size()))]) continue; p1 = malla->getNodo(ind_nodos[i])->getPunto(); p2 = malla->getNodo(ind_nodos[int(fmod(i+1,num_elem))])->getPunto(); p3 = malla->getNodo(ind_nodos[int(fmod(i+2,num_elem))])->getPunto(); Vect vp1(p1); Vect vp2(p2); Vect vp3(p3); v1 = vp1 - vp2; v2 = vp3 - vp2; angulo = v1.getAngulo(v2); return angulo; } // el indice del nodo no pertenece a la cara assert(false); return 0; }
/** * Draws the meta grid. * * @see drawIt() */ void RS_GraphicView::drawMetaGrid(RS_Painter *painter) { if (!(grid && isGridOn()) /*|| grid->getMetaSpacing()<0.0*/) { return; } //draw grid after metaGrid to avoid overwriting grid points by metaGrid lines //bug# 3430258 grid->updatePointArray(); RS_Pen pen(metaGridColor, RS2::Width00, RS2::DotLine); painter->setPen(pen); RS_Vector dv=grid->getMetaGridWidth().scale(factor); double dx=fabs(dv.x); double dy=fabs(dv.y); //potential bug, need to recover metaGrid.width // draw meta grid: auto mx = grid->getMetaX(); for(auto const& x: mx){ painter->drawLine(RS_Vector(toGuiX(x), 0), RS_Vector(toGuiX(x), getHeight())); if(grid->isIsometric()){ painter->drawLine(RS_Vector(toGuiX(x)+0.5*dx, 0), RS_Vector(toGuiX(x)+0.5*dx, getHeight())); } } auto my = grid->getMetaY(); if(grid->isIsometric()){//isometric metaGrid dx=fabs(dx); dy=fabs(dy); if(!my.size()|| dx<1||dy<1) return; RS_Vector baseMeta(toGui(RS_Vector(mx[0],my[0]))); // x-x0=k*dx, x-remainder(x-x0,dx) RS_Vector vp0(-remainder(-baseMeta.x,dx)-dx,getHeight()-remainder(getHeight()-baseMeta.y,dy)+dy); RS_Vector vp1(vp0); RS_Vector vp2(getWidth()-remainder(getWidth()-baseMeta.x,dx)+dx,vp0.y); RS_Vector vp3(vp2); int cmx = round((vp2.x - vp0.x)/dx); int cmy = round((vp0.y +remainder(-baseMeta.y,dy)+dy)/dy); for(int i=cmx+cmy+2;i>=0;i--){ if ( i <= cmx ) { vp0.x += dx; vp2.y -= dy; }else{ vp0.y -= dy; vp2.x -= dx; } if ( i <= cmy ) { vp1.y -= dy; vp3.x -= dx; }else{ vp1.x += dx; vp3.y -= dy; } painter->drawLine(vp0,vp1); painter->drawLine(vp2,vp3); } }else{//orthogonal for(auto const& y: my){ painter->drawLine(RS_Vector(0, toGuiY(y)), RS_Vector(getWidth(), toGuiY(y))); } } }