void apprentissageAleatoire(fonction& g, bool first_pass, bool record){ BaseEtats baseEtats; Thetas thetarandom; Thetas dtheta; Thetas dthetamin; Rayon rmin; Rayon r; std::list<gaml::libsvm::Predictor<Entree,double>> predictors; std::array<std::string,4> filenames = {{std::string("theta1.pred"),"theta2.pred","theta3.pred","theta4.pred"}}; for (int j=0;j< NB_TESTS_PAR_PHASE;j++){ std::cout<<"Nouvelle boucle mise a jour de f"<<std::endl; std::cout<<"____________________"<< std::endl; std::cout<<"Nouvel essai random n°"<<j<<std::endl; r = {0,0,0}; while(r[0] == 0 && r[1] == 0 && r[2] == 0){ thetarandom = creationThetaRandom(); moveArm(thetarandom); r = vecteur_kinnect_objet(); } if(first_pass){ dtheta = {.0,.0,.0,.0}; }else{ auto res = g({r[0],r[1],r[2],thetarandom[0],thetarandom[1],thetarandom[2],thetarandom[3]}); dtheta = { res.theta1, res.theta2, res.theta3, res.theta4 }; } moveArm(thetarandom+dtheta); rmin = vecteur_kinnect_objet(); std::cout<<"Thetas :"<<thetarandom<<" | Rayon :"<<r<< " | Distance :"<<norme(r)<<" | dthetas :"<<dtheta<<std::endl; dthetamin = oscillations(r,thetarandom,rmin,dtheta); Etat etat (r,thetarandom,dthetamin); baseEtats.push_back(etat); std::cout<<"Amelioration dthetas : "<<dthetamin<<std::endl; } std::cout<<"mise a jour de f"<<std::endl; g = calcul_f(baseEtats,record); }
SVector3 gmshFace::normal(const SPoint2 ¶m) const { if(s->Typ != MSH_SURF_PLAN){ Vertex vu = InterpolateSurface(s, param[0], param[1], 1, 1); Vertex vv = InterpolateSurface(s, param[0], param[1], 1, 2); Vertex n = vu % vv; n.norme(); return SVector3(n.Pos.X, n.Pos.Y, n.Pos.Z); } else{ // We cannot use InterpolateSurface() for plane surfaces since it // relies on the mean plane, which does not respect the // orientation // FIXME: move this test at the end of the MeanPlane computation // routine--and store the correct normal, damn it! double n[3] = {meanPlane.a, meanPlane.b, meanPlane.c}; norme(n); GPoint pt = point(param.x(), param.y()); double v[3] = {pt.x(), pt.y(), pt.z()}; int NP = 10, tries = 0; while(1){ tries++; double angle = 0.; for(int i = 0; i < List_Nbr(s->Generatrices); i++) { Curve *c; List_Read(s->Generatrices, i, &c); int N = (c->Typ == MSH_SEGM_LINE) ? 1 : NP; for(int j = 0; j < N; j++) { double u1 = (double)j / (double)N; double u2 = (double)(j + 1) / (double)N; Vertex p1 = InterpolateCurve(c, u1, 0); Vertex p2 = InterpolateCurve(c, u2, 0); double v1[3] = {p1.Pos.X, p1.Pos.Y, p1.Pos.Z}; double v2[3] = {p2.Pos.X, p2.Pos.Y, p2.Pos.Z}; angle += angle_plan(v, v1, v2, n); } } if(fabs(angle) < 0.5){ // we're outside NP *= 2; Msg::Debug("Could not compute normal of surface %d - retrying with %d points", tag(), NP); if(tries > 10){ Msg::Warning("Could not orient normal of surface %d", tag()); return SVector3(n[0], n[1], n[2]); } } else if(angle > 0) return SVector3(n[0], n[1], n[2]); else return SVector3(-n[0], -n[1], -n[2]); } } }
void normalise(MCOORD *v) { GLdouble norm = norme(*v); if(norm > 0.0000001) { v->x /= norm; v->y /= norm; v->z /= norm; } else { v->x = 0.0; v->y = 0.0; v->z = 0.0; } }
double calc_k_sphere(t_vect *o, t_vect *u, t_obj *obj) { t_vect tmp; double x1; double x2; tmp.x = (u->x * u->x + u->y * u->y + u->z * u->z); tmp.y = 2 * (o->x * u->x + o->y * u->y + o->z * u->z); tmp.z = (o->x * o->x + o->y * o->y + o->z * o->z - obj->param * obj->param); if (res_eq_sc(&tmp, &x1, &x2)) { if ((x1 * norme(u)) > PAS && x1 < x2 && check_limit(o, u, x1, obj)) return (x1); else if ((x2 * norme(u)) > PAS && check_limit(o, u, x2, obj)) return (x2); else return (-1); } else return (-1); }
quint8 KisCircleMaskGenerator::valueAt(qreal x, qreal y) const { if (isEmpty()) return 255; qreal xr = (x /*- m_xcenter*/); qreal yr = qAbs(y /*- m_ycenter*/); fixRotation(xr, yr); qreal n = norme(xr * d->xcoef, yr * d->ycoef); if (n > 1.0) return 255; // we add +1.0 to ensure correct antialising on the border if (antialiasEdges()) { xr = qAbs(xr) + 1.0; yr = qAbs(yr) + 1.0; } qreal nf = norme(xr * d->transformedFadeX, yr * d->transformedFadeY); if (nf < 1.0) return 0; return 255 * n * (nf - 1.0) / (nf - n); }
double qmQuadrangleAngles (MQuadrangle *e) { double a = 100; double worst_quality = std::numeric_limits<double>::max(); double mat[3][3]; double mat2[3][3]; double den = atan(a*(M_PI/4)) + atan(a*(2*M_PI/4 - (M_PI/4))); // This matrix is used to "rotate" the triangle to get each vertex // as the "origin" of the mapping in turn //double rot[3][3]; //rot[0][0]=-1; rot[0][1]=1; rot[0][2]=0; //rot[1][0]=-1; rot[1][1]=0; rot[1][2]=0; //rot[2][0]= 0; rot[2][1]=0; rot[2][2]=1; //double tmp[3][3]; const double u[9] = {-1,-1, 1, 1, 0,0,1,-1,0}; const double v[9] = {-1, 1, 1,-1, -1,1,0,0,0}; for (int i = 0; i < 9; i++) { e->getJacobian(u[i], v[i], 0, mat); e->getPrimaryJacobian(u[i],v[i],0,mat2); //for (int j = 0; j < i; j++) { // matmat(rot,mat,tmp); // memcpy(mat, tmp, sizeof(mat)); //} //get angle double v1[3] = {mat[0][0], mat[0][1], mat[0][2] }; double v2[3] = {mat[1][0], mat[1][1], mat[1][2] }; double v3[3] = {mat2[0][0], mat2[0][1], mat2[0][2] }; double v4[3] = {mat2[1][0], mat2[1][1], mat2[1][2] }; norme(v1); norme(v2); norme(v3); norme(v4); double v12[3], v34[3]; prodve(v1,v2,v12); prodve(v3,v4,v34); norme(v12); norme(v34); double orientation; prosca(v12,v34,&orientation); // If the if the triangle is "flipped" it's no good // if (orientation < 0) // return -std::numeric_limits<double>::max(); double c; prosca(v1,v2,&c); double x = fabs(acos(c))-M_PI/2; //double angle = fabs(acos(c))*180/M_PI; double quality = (atan(a*(x+M_PI/4)) + atan(a*(2*M_PI/4 - (x+M_PI/4))))/den; worst_quality = std::min(worst_quality, quality); } return worst_quality; }
static int read_get_next_line(const int fd, char **line, char **rest) { int tete; if (*rest == NULL) *rest = ft_strnew(BUFF_SIZE); else if (ft_strchr(*rest, '\n') != NULL) return (ft_cop(rest, line, rest)); else if ((*line = ft_strjoin(*line, *rest)) == NULL) return (-1); if (norme(fd, line, rest, &tete) == 1) return (1); return (tete); }
int main(int ac, char **av) { if (debut(ac, av[1]) == 0 && atoi(av[1]) > 0 && (av[2][0] >= 49 && av[2][0] <= 57)) { srand(time(NULL)); int a = atoi(av[2]); int b = rand()%(9+10)-9; int tabA[a], tabB[a] , tabAB[a], tabMult[a]; printf("Vecteur A:\t"); nbrAlea(a, tabA); affiche(tabA, a); printf("\n"); if (atoi(av[1]) != 2) { printf("Vecteur B:\t"); nbrAlea(a, tabB); affiche(tabB, a); printf("\n"); } if (atoi(av[1]) == 1) { printf("Vecteur A+B:\t"); somme(a, tabA, tabB, tabAB); affiche(tabAB, a); } else if (atoi(av[1]) == 2) { printf(" B: %d\nVecteur A*B:\t", b); multi(a, tabA, tabMult, b); affiche(tabMult, a); } else if (atoi(av[1]) == 3) { printf("Produit Scalaire AB:\t"); printf("%d", scal(a, tabA, tabB)); } else if (atoi(av[1]) == 4) { printf("Norme Euclidienne A.B:\t"); somme(a, tabA, tabB, tabAB); printf("%.3f", sqrt(norme(a, tabAB))); } printf("\n"); } else printf("Veuillez entrer en argument un nombre compris entre 1 et 4 suivi du nombre de coordonnee que vous voulez \n"); return (0); }
t_vector3 unitaire(t_vector3 v) { double norm; t_vector3 uni; norm = norme(v); if (norm) { uni.x = v.x / norm; uni.y = v.y / norm; uni.z = v.z / norm; } return (uni); }
void jacobi (double** a, double** b, double** xInit, int n, double prec) { int i, j, cpt; double residu=2*prec; double** xNext= (double**) malloc(n*sizeof(double*)); double** ax; double** axb; cpt=0; for (i=0; i<n; i++) //initialisation xNext { xNext[i]= (double*) malloc(sizeof(double)); } while (residu>=prec) { for (i=0; i<n; i++) { double somme1=0, somme2=0; for (j=0; j<i; j++) //avant l'élément diagonal { somme1=somme1+a[i][j]*xInit[j][0]; } for (j=i+1; j<n; j++) //après l'élément diagonal { somme2=somme2+a[i][j]*xInit[j][0]; } xNext[i][0]=(1/a[i][i])*(b[i][0]-somme1-somme2); } for(i=0; i<n; i++) { xInit[i][0] = xNext[i][0] ; //copie de xNext dans xInit pour la prochaine itération } ax=produitMatriciel(a, xNext, n, n, 1); //ax axb=difference(ax, b, n, 1); //ax - b residu=norme(axb, n); //norme de (ax - b) cpt++; //affichage printf("\nVecteur à l'itération %d :\n", cpt); afficherMatrice(xNext, n, 1); } //libération mémoire for (i=0;i<n;i++) { free(ax[i]); free(axb[i]); free(xNext[i]); } free(ax); free(axb); free(xNext); }
int IsoSimplex(double *X, double *Y, double *Z, double *Val, double V, double *Xp, double *Yp, double *Zp, double n[3]) { if(Val[0] == Val[1] && Val[0] == Val[2] && Val[0] == Val[3]) return 0; int nb = 0; if((Val[0] >= V && Val[1] <= V) || (Val[1] >= V && Val[0] <= V)) { InterpolateIso(X, Y, Z, Val, V, 0, 1, &Xp[nb], &Yp[nb], &Zp[nb]); nb++; } if((Val[0] >= V && Val[2] <= V) || (Val[2] >= V && Val[0] <= V)) { InterpolateIso(X, Y, Z, Val, V, 0, 2, &Xp[nb], &Yp[nb], &Zp[nb]); nb++; } if((Val[0] >= V && Val[3] <= V) || (Val[3] >= V && Val[0] <= V)) { InterpolateIso(X, Y, Z, Val, V, 0, 3, &Xp[nb], &Yp[nb], &Zp[nb]); nb++; } if((Val[1] >= V && Val[2] <= V) || (Val[2] >= V && Val[1] <= V)) { InterpolateIso(X, Y, Z, Val, V, 1, 2, &Xp[nb], &Yp[nb], &Zp[nb]); nb++; } if((Val[1] >= V && Val[3] <= V) || (Val[3] >= V && Val[1] <= V)) { InterpolateIso(X, Y, Z, Val, V, 1, 3, &Xp[nb], &Yp[nb], &Zp[nb]); nb++; } if((Val[2] >= V && Val[3] <= V) || (Val[3] >= V && Val[2] <= V)) { InterpolateIso(X, Y, Z, Val, V, 2, 3, &Xp[nb], &Yp[nb], &Zp[nb]); nb++; } // Remove identical nodes (this can happen if an edge belongs to the // zero levelset). We should be doing this even for nb < 4, but it // would slow us down even more (and we don't really care if some // nodes in a postprocessing element are identical) if(nb > 4) { double xi[6], yi[6], zi[6]; affect(xi, yi, zi, 0, Xp, Yp, Zp, 0); int ni = 1; for(int j = 1; j < nb; j++) { for(int i = 0; i < ni; i++) { if(fabs(Xp[j] - xi[i]) < 1.e-12 && fabs(Yp[j] - yi[i]) < 1.e-12 && fabs(Zp[j] - zi[i]) < 1.e-12) { break; } if(i == ni - 1) { affect(xi, yi, zi, i + 1, Xp, Yp, Zp, j); ni++; } } } for(int i = 0; i < ni; i++) affect(Xp, Yp, Zp, i, xi, yi, zi, i); nb = ni; } if(nb < 3 || nb > 4) return 0; // 3 possible quads at this point: (0,2,5,3), (0,1,5,4) or // (1,2,4,3), so simply invert the 2 last vertices for having the // quad ordered if(nb == 4) { double x = Xp[3], y = Yp[3], z = Zp[3]; Xp[3] = Xp[2]; Yp[3] = Yp[2]; Zp[3] = Zp[2]; Xp[2] = x; Yp[2] = y; Zp[2] = z; } // to get a nice isosurface, we should have n . grad v > 0, where n // is the normal to the polygon and v is the unknown field we want // to draw double v1[3] = {Xp[2] - Xp[0], Yp[2] - Yp[0], Zp[2] - Zp[0]}; double v2[3] = {Xp[1] - Xp[0], Yp[1] - Yp[0], Zp[1] - Zp[0]}; prodve(v1, v2, n); norme(n); double g[3]; gradSimplex(X, Y, Z, Val, g); double gdotn; prosca(g, n, &gdotn); if(gdotn > 0.) { double Xpi[6], Ypi[6], Zpi[6]; for(int i = 0; i < nb; i++) { Xpi[i] = Xp[i]; Ypi[i] = Yp[i]; Zpi[i] = Zp[i]; } for(int i = 0; i < nb; i++) { Xp[i] = Xpi[nb - i - 1]; Yp[i] = Ypi[nb - i - 1]; Zp[i] = Zpi[nb - i - 1]; } } else { n[0] = -n[0]; n[1] = -n[1]; n[2] = -n[2]; } return nb; }
Vector3& Vector3::normalise() { return ((*this)/=norme()); }
double qmTriangleAngles (MTriangle *e) { double a = 500; double worst_quality = std::numeric_limits<double>::max(); double mat[3][3]; double mat2[3][3]; double den = atan(a*(M_PI/9)) + atan(a*(M_PI/9)); // This matrix is used to "rotate" the triangle to get each vertex // as the "origin" of the mapping in turn double rot[3][3]; rot[0][0]=-1; rot[0][1]=1; rot[0][2]=0; rot[1][0]=-1; rot[1][1]=0; rot[1][2]=0; rot[2][0]= 0; rot[2][1]=0; rot[2][2]=1; double tmp[3][3]; //double minAngle = 120.0; for (int i = 0; i < e->getNumPrimaryVertices(); i++) { const double u = i == 1 ? 1 : 0; const double v = i == 2 ? 1 : 0; const double w = 0; e->getJacobian(u, v, w, mat); e->getPrimaryJacobian(u,v,w,mat2); for (int j = 0; j < i; j++) { matmat(rot,mat,tmp); memcpy(mat, tmp, sizeof(mat)); } //get angle double v1[3] = {mat[0][0], mat[0][1], mat[0][2] }; double v2[3] = {mat[1][0], mat[1][1], mat[1][2] }; double v3[3] = {mat2[0][0], mat2[0][1], mat2[0][2] }; double v4[3] = {mat2[1][0], mat2[1][1], mat2[1][2] }; norme(v1); norme(v2); norme(v3); norme(v4); double v12[3], v34[3]; prodve(v1,v2,v12); prodve(v3,v4,v34); norme(v12); norme(v34); double orientation; prosca(v12,v34,&orientation); // If the triangle is "flipped" it's no good if (orientation < 0) return -std::numeric_limits<double>::max(); double c; prosca(v1,v2,&c); double x = acos(c)-M_PI/3; //double angle = (x+M_PI/3)/M_PI*180; double quality = (atan(a*(x+M_PI/9)) + atan(a*(M_PI/9-x)))/den; worst_quality = std::min(worst_quality, quality); //minAngle = std::min(angle, minAngle); //printf("Angle %g ", angle); // printf("Quality %g\n",quality); } //printf("MinAngle %g \n", minAngle); //return minAngle; return worst_quality; }
double Vector3D::angle(const Vector3D& vec) const { if(vec.estNul()) return 0; return acos(produitScalaire(vec)/(norme()*vec.norme())); }
PView *GMSH_SphericalRaisePlugin::execute(PView *v) { double center[3]; center[0] = SphericalRaiseOptions_Number[0].def; center[1] = SphericalRaiseOptions_Number[1].def; center[2] = SphericalRaiseOptions_Number[2].def; double raise = SphericalRaiseOptions_Number[3].def; double offset = SphericalRaiseOptions_Number[4].def; int timeStep = (int)SphericalRaiseOptions_Number[5].def; int iView = (int)SphericalRaiseOptions_Number[6].def; PView *v1 = getView(iView, v); if(!v1) return v; PViewData *data1 = v1->getData(); // sanity checks if(timeStep < 0 || timeStep > data1->getNumTimeSteps() - 1){ Msg::Error("Invalid TimeStep (%d) in view", timeStep); return v; } if(data1->isNodeData()){ // tag all the nodes with "0" (the default tag) for(int step = 0; step < data1->getNumTimeSteps(); step++){ for(int ent = 0; ent < data1->getNumEntities(step); ent++){ for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ if(data1->skipElement(step, ent, ele)) continue; for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) data1->tagNode(step, ent, ele, nod, 0); } } } } // transform all "0" nodes for(int step = 0; step < data1->getNumTimeSteps(); step++){ for(int ent = 0; ent < data1->getNumEntities(step); ent++){ for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ if(data1->skipElement(step, ent, ele)) continue; for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++){ double x, y, z; int tag = data1->getNode(step, ent, ele, nod, x, y, z); if(data1->isNodeData() && tag) continue; double r[3], val; r[0] = x - center[0]; r[1] = y - center[1]; r[2] = z - center[2]; norme(r); data1->getScalarValue(step, ent, ele, nod, val); double coef = offset + raise * val; x += coef * r[0]; y += coef * r[1]; z += coef * r[2]; data1->setNode(step, ent, ele, nod, x, y, z); if(data1->isNodeData()) data1->tagNode(step, ent, ele, nod, 1); } } } } data1->finalize(); v1->setChanged(true); return v1; }
float Trantorien::scalaire(const glm::vec2 &v1, const glm::vec2 &v2) { return (acos((v1.x * v2.x + v1.y * v2.y) / (norme(v1) * norme(v2)))); }
void Vecteur::normaliser() { *this /= norme(); }
Vecteur normaliser(Vecteur a){ return CreerVecteur(a.x/norme(a), a.y/norme(a)); }