这篇教程C++ vector_length函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中vector_length函数的典型用法代码示例。如果您正苦于以下问题:C++ vector_length函数的具体用法?C++ vector_length怎么用?C++ vector_length使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了vector_length函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: vector_lengthSpriteSheet& SpriteSheet::add_frame(const std::vector<sf::Vector2f>& points){ auto width = vector_length(points[0] - points[1]); auto height = vector_length(points[0] - points[2]); FrameInfo frame = { { sf::Vector2f(0, 0), sf::Vector2f(0, height), sf::Vector2f(width, height), sf::Vector2f(width, 0), }, { points[0], points[1], points[2], points[3], }, {0, 0, width, height } }; m_frames.push_back(frame); return *this;}
开发者ID:fpischedda,项目名称:sfml_sprite_sheet,代码行数:25,
示例2: scalar_opstatic void scalar_op(Array arr, double s, char op, Array ans)/* Elementwise scalar operations */{ int i; assert (test_array_conform(arr, ans)); switch (op) { case '*': for (i = 0; i < vector_length(ans); i++) VECTOR(ans)[i] = VECTOR(arr)[i] * s; break; case '+': for (i = 0; i < vector_length(ans); i++) VECTOR(ans)[i] = VECTOR(arr)[i] + s; break; case '/': for (i = 0; i < vector_length(ans); i++) VECTOR(ans)[i] = VECTOR(arr)[i] / s; break; case '-': for (i = 0; i < vector_length(ans); i++) VECTOR(ans)[i] = VECTOR(arr)[i] - s; break; default: printf("Unknown op in array_op"); }}
开发者ID:jeffreyhorner,项目名称:cxxr,代码行数:28,
示例3: __bounding_get_effective_positionstatic void __bounding_get_effective_position(const Bounding *b, Vector *result){ assert(b && "Bad bounding pointer."); assert(b->origin && b->previous_origin && b->orientation && b->direction && "Bad bounding data."); assert(result && "Bad result pointer."); Vector p = *b->origin, t, side; if (!vector_eq(b->orientation, b->direction)) { vector_vector_mul(b->orientation, b->direction, &side); } else { vector_get_orthogonal(b->direction, &side); } VECTOR_NORMALIZE(&side); double sx, sy, sz; vector_scale(b->direction, b->offset.x, &t); sx = vector_length(&t); vector_scale(&side, b->offset.y, &t); sy = vector_length(&t); vector_scale(b->orientation, b->offset.z, &t); sz = vector_length(&t); p.x += sx; p.y += sy; p.z += sz; *result = p;}
开发者ID:aquirel,项目名称:morrigan,代码行数:33,
示例4: array_opstatic void array_op(Array arr1, Array arr2, char op, Array ans)/* Element-wise array operations */{ int i; assert (test_array_conform(arr1, arr2)); assert (test_array_conform(arr2, ans)); switch (op) { case '*': for (i = 0; i < vector_length(ans); i++) VECTOR(ans)[i] = VECTOR(arr1)[i] * VECTOR(arr2)[i]; break; case '+': for (i = 0; i < vector_length(ans); i++) VECTOR(ans)[i] = VECTOR(arr1)[i] + VECTOR(arr2)[i]; break; case '/': for (i = 0; i < vector_length(ans); i++) VECTOR(ans)[i] = VECTOR(arr1)[i] / VECTOR(arr2)[i]; break; case '-': for (i = 0; i < vector_length(ans); i++) VECTOR(ans)[i] = VECTOR(arr1)[i] - VECTOR(arr2)[i]; break; default: printf("Unknown op in array_op"); }}
开发者ID:jeffreyhorner,项目名称:cxxr,代码行数:29,
示例5: thread_schedule/* FIXME: incompatible with current design of soft-method-calling */VALUEthread_schedule(){ int i; VALUE th; /* don't increment round-robin count if in critical section */ if ( TEST(thr_crit) || (vector_length(thr_stk) <= 1) ) { if (!THREAD(cur_thr)->alive_p) thread_deadlock(); return cur_thr; } /* find the highest priority thread; lowest round-robin count otherwise */ for (i = 0; i < vector_length(thr_stk); i++) { th = (VALUE)vector_aref(thr_stk, i); if ( (THREAD(th)->prio > THREAD(cur_thr)->prio) || (!(THREAD(th)->prio < THREAD(cur_thr)->prio) && (THREAD(th)->cnt < THREAD(cur_thr)->cnt)) ) { if (THREAD(th)->alive_p) cur_thr = (VALUE)vector_aref(thr_stk, i); else THREAD(th)->cnt++; } } THREAD(cur_thr)->cnt++; return cur_thr;}
开发者ID:mtmiron,项目名称:toi,代码行数:32,
示例6: constr_scalevoid constr_scale(float A[3], float B[3], float C[3], float D[3], float fixed_point[3], int g) /* scales group by |AB|/|CD| */{ double lAB,lCD,s; float AB[3], CD[3]; vector_sub(B, A, AB); vector_sub(D, C, CD); lAB=vector_length(AB); lCD=vector_length(CD); if(lCD==0) { printf("scaling refused: |CD| = 0 !!!/n"); return; } s=lAB/lCD; if(s== 1.0) { printf("scaling by 1 does not change anything !!!/n"); return; } backup(); group_scale(g, s, s, s, fixed_point, group, vertex, vertex_used);}
开发者ID:mki1967,项目名称:et-edit,代码行数:27,
示例7: dice_coefficientstatic double dice_coefficient(const double *vec1, const double *vec2, size_t veclen, bool normalize){ if (!vec1 && !vec2) return 1.0 ; else if (!vec1 || !vec2) return (veclen == 0) ? 1.0 : 0.0 ;// no overlap, but same if zero-length double prod(0.0) ; double sum(0.0) ; if (normalize) { double length1 = vector_length(vec1,veclen) ; double length2 = vector_length(vec2,veclen) ; // prevent division by zero -- if ||vector|| is zero, all elements are // zero, so it doesn't matter what we divide by; pick 1.0 if (length1 == 0) length1 = 1.0 ; if (length2 == 0) length2 = 1.0 ; for (size_t i = 0 ; i < veclen ; i++) { double v1 = vec1[i] / length1 ; double v2 = vec2[i] / length2 ; prod += (v1 * v2) ; sum += (v1 + v2) ; } } else { for (size_t i = 0 ; i < veclen ; i++) { prod += (vec1[i] * vec2[i]) ; sum += (vec1[i] + vec2[i]) ; } } return (sum > 0.0) ? (2.0 * prod / sum) : 0.0 ;}
开发者ID:ralfbrown,项目名称:framepac,代码行数:35,
示例8: manhattan_distancestatic double manhattan_distance(const double *vec1, const double *vec2, size_t veclen, bool normalize){ double distance = 0.0 ; if (normalize) { double length1 = vector_length(vec1,veclen) ; double length2 = vector_length(vec2,veclen) ; // prevent division by zero -- if ||vector|| is zero, all elements are // zero, so it doesn't matter what we divide by; pick 1.0 if (length1 == 0) length1 = 1.0 ; if (length2 == 0) length2 = 1.0 ; for (size_t i = 0 ; i < veclen ; i++) { distance += fabs((vec1[i] / length1) - (vec2[i] / length2)) ; } } else { for (size_t i = 0 ; i < veclen ; i++) { distance += fabs(vec1[i] - vec2[i]) ; } } return distance ;}
开发者ID:ralfbrown,项目名称:framepac,代码行数:26,
示例9: circle_productstatic double circle_product(const double *vec1, const double *vec2, size_t veclen, bool normalize){ if (!vec1 || !vec2) return 0.0 ; double sum(0.0) ; if (normalize) { double length1 = vector_length(vec1,veclen) ; double length2 = vector_length(vec2,veclen) ; // prevent division by zero -- if ||vector|| is zero, all elements are // zero, so it doesn't matter what we divide by; pick 1.0 if (length1 == 0) length1 = 1.0 ; if (length2 == 0) length2 = 1.0 ; for (size_t i = 0 ; i < veclen ; i++) { double v1 = vec1[i] / length1 ; double v2 = vec2[i] / length2 ; sum += minimum(v1,v2) ; } } else { for (size_t i = 0 ; i < veclen ; i++) { double v1 = vec1[i] ; double v2 = vec2[i] ; sum += minimum(v1,v2) ; } } return sum ;}
开发者ID:ralfbrown,项目名称:framepac,代码行数:32,
示例10: TEST_FTEST_F(Vector2Test, orthonormal_basis_creates_perpendicular_vectors_of_length_1){ if (random_vector != random_vector2) { generate_orthonormal_basis(random_vector, random_vector2); EXPECT_NEAR(0.0, dot_product(random_vector, random_vector2), PRECISION); EXPECT_NEAR(1.0, vector_length(random_vector), PRECISION); EXPECT_NEAR(1.0, vector_length(random_vector2), PRECISION); }}
开发者ID:martiert,项目名称:Pandora3D,代码行数:9,
示例11: mainvoid main( int argc, char **argv){ double state_vect2[6], jd = atof( argv[3]); const int home_planet = atoi( argv[1]), planet_no = atoi( argv[2]); double dist = 0., pvsun[6]; int i, pass, center = 12; void *p; char *filename; if( argc > 4) center = atoi( argv[4]); printf( "Year approx %.3lf/n", 2000. + (jd - 2451545.) / 365.25); filename = "d://guide_b//jpl_eph//sub_de.406"; p = jpl_init_ephemeris( filename, NULL, NULL); if( !p) { printf( "JPL data not loaded/n"); exit( -1); } jpl_pleph( p, jd, center, home_planet, state_vect2, 1); printf( "Observer state vector:/n"); show_state_vector( state_vect2);// for( i = 0; i < 3; i++)// pvsun[i] = jpl_get_pvsun( p)[i]; for( pass = 0; pass < 4; pass++) { double state_vect[6], ang; char buff[30]; jpl_pleph( p, jd - dist * AU_IN_KM / (SPEED_OF_LIGHT * 86400.), center, planet_no, state_vect, 1); if( pass == 3) { for( i = 0; i < 3; i++) pvsun[i] = state_vect[i] + jpl_get_pvsun( p)[i];// pvsun[i] += state_vect[i]; printf( "%.11lf %.11lf %.11lf/n", pvsun[0], pvsun[1], pvsun[2]); printf( "Dist to sun: %.11lf/n", vector_length( pvsun)); } for( i = 0; i < 6; i++) state_vect[i] -= state_vect2[i]; dist = vector_length( state_vect); show_state_vector( state_vect); ang = atan2( state_vect[1], state_vect[0]) * 12. / PI; format_base_sixty( buff, ang + 12.); buff[15] = '/0'; printf( "%s ", buff + 1); /* skip leading '+' */ ang = -asin( state_vect[2] / dist) * 180. / PI; format_base_sixty( buff, ang); buff[14] = '/0'; printf( "%s %.11lf (%.3lf km)/n", buff, dist, dist * AU_IN_KM); } jpl_close_ephemeris( p);}
开发者ID:nachoplus,项目名称:tychoCatServer,代码行数:56,
示例12: inline boolformula_t *cdnfformula_to_boolformula (conjunction * f) { boolformula_t* ret=boolformula_conjunction_new(vector_length(f)), *temp; uscalar_t i; for (i = 0; i < vector_length (f); i++) { temp=dnf_to_boolformula(vector_get(f,i)); boolformula_set(ret, i, temp); boolformula_free(temp); } return ret;}
开发者ID:rowangithub,项目名称:DOrder,代码行数:10,
示例13: temp_vertex_normalvoid SCANLINE::Compute_Poly_Normal(){ vector< vector<float> > temp_vertex_normal(world_vertex.size(),vector<float>(3)); vector <float> temp_I_light(3);//light intensity I_light = temp_I_light; I_light[0] = 1.0;//R I_light[1] = 0.64;//G I_light[2] = 0;//B vector <float> poly_vector_1(3); vector <float> poly_vector_2(3); vector <float> poly_normal(3); vector <float> temp_H(3); //calculus H vector_summation(temp_H, vec_light,vec_view); for (int j=0; j<3 ;j++ ) H_specular.push_back(temp_H[j]/vector_length(temp_H)); ///---Intensity ambient----Ka*I for (int j=0; j<3 ;j++ ) Intensity_ambient.push_back(K_ambient*I_light[j]); for(int i=0; i<(int)Poly.size(); i++) {//compute polygon normal vector_subtraction(poly_vector_1, world_vertex[Poly[i][2]-1], world_vertex[Poly[i][1]-1]); vector_subtraction(poly_vector_2, world_vertex[Poly[i][2]-1], world_vertex[Poly[i][3]-1]); //compute 2 vector on one polygon cross_product3D(poly_normal, poly_vector_1, poly_vector_2); //calculus cross product for(int j=1; j<(int)Poly[i][0]+1 ;j++) {//add normal of neibor polygon to vertex for (int p=0; p<3 ;p++ ) temp_vertex_normal[Poly[i][j]-1][p] += poly_normal[p]; } } for(int i=0; i<(int)temp_vertex_normal.size() ;i++ ) { float temp_length = vector_length(temp_vertex_normal[i]); for (int j=0; j<3 ;j++ ) { //normalize the normal on vertex temp_vertex_normal[i][j] = temp_vertex_normal[i][j] / temp_length; } } vertex_normal = temp_vertex_normal; //vertex normals as average of surrounding neibor polygon's normal}
开发者ID:jlyharia,项目名称:Computer_GraphicsII,代码行数:54,
示例14: monomial_to_boolformulainline boolformula_t* monomial_to_boolformula (monomial *m){ boolformula_t* ret=boolformula_conjunction_new(vector_length(m)),*temp; uscalar_t i; for (i = 0; i < vector_length (m); i++) { temp=boolformula_literal_new((lit)vector_get(m,i)); boolformula_set(ret, i, temp); boolformula_free(temp); } return ret;}
开发者ID:rowangithub,项目名称:DOrder,代码行数:12,
示例15: constr_scale_in_directionvoid constr_scale_in_direction(float A[3], float B[3], float C[3], float D[3], float E[3], float F[3], float fixed_point[3], int g) /* scales group by |AB|/|CD| in direction EF */{ double lAB,lCD,s; float AB[3], CD[3], EF[3], v[3], tmp[3]; double sp; int i; if(vector_eq(E,F)) { printf("scaling in direction EF refused: EF = 0 !!!/n"); return; } vector_sub(B, A, AB); vector_sub(D, C, CD); vector_sub(F, E, EF); vector_normalize(EF); lAB=vector_length(AB); lCD=vector_length(CD); if(lCD==0) { printf("scaling refused: |CD| = 0 !!!/n"); return; } s=lAB/lCD; if(s== 1.0) { printf("scaling by 1 does not change anything !!!/n"); return; } backup(); for(i=0; i<VERTEX_MAX; i++) if(vertex_used[i] && group[i]==g) { vector_sub(vertex[i], fixed_point, v); sp=scalar_product(EF,v); vectorcpy(tmp, EF); vector_scale((s-1)*sp, tmp); vector_add(v,tmp, v); vector_add(v, fixed_point, vertex[i]); }}
开发者ID:mki1967,项目名称:et-edit,代码行数:49,
示例16: cdnfformula_monomial_to_stringstatic void cdnfformula_monomial_to_string (monomial *m){ if (vector_length (m) == 0) { fprintf (stderr, "( T )"); } else { uscalar_t i; fprintf (stderr, "( "); for (i = vector_length (m) - 1; i > 0; i--) { fprintf (stderr, "%ld & ", (lit) vector_get (m, i)); } assert (i == 0); fprintf (stderr, "%ld ", (lit) vector_get (m, i)); fprintf (stderr, " )"); }}
开发者ID:rowangithub,项目名称:DOrder,代码行数:15,
示例17: cdnfformula_printvoid cdnfformula_print (conjunction *f){ if (vector_length (f) == 0) { fprintf (stderr, "{ T }"); } else { uscalar_t i; fprintf (stderr, "{ "); for (i = vector_length (f) - 1; i > 0; i--) { cdnfformula_disjunction_to_string (vector_get (f, i)); fprintf (stderr, " & "); } assert (i == 0); cdnfformula_disjunction_to_string (vector_get (f, i)); fprintf (stderr, " }/n"); }}
开发者ID:rowangithub,项目名称:DOrder,代码行数:16,
示例18: cdnfformula_disjunction_to_stringstatic void cdnfformula_disjunction_to_string (disjunction *f){ if (vector_length (f) == 0) { fprintf (stderr, "[ F ]"); } else { uscalar_t i; fprintf (stderr, "[ "); for (i = vector_length (f) - 1; i > 0; i--) { cdnfformula_monomial_to_string (vector_get (f, i)); fprintf (stderr, " | "); } assert (i == 0); cdnfformula_monomial_to_string (vector_get (f, i)); fprintf (stderr, " ]"); }}
开发者ID:rowangithub,项目名称:DOrder,代码行数:16,
示例19: nblist_pair_distancesstatic PyObject *nblist_pair_distances(PyObject *self, PyObject *args){ PyNonbondedListObject *nblist = (PyNonbondedListObject *)self; struct nblist_iterator iterator; PyArrayObject *array; vector3 dv; double *d; int i;#if defined(NUMPY) npy_intp n;#else int n;#endif if (!PyArg_ParseTuple(args, "")) return NULL; n = nblist_length(nblist);#if defined(NUMPY) array = (PyArrayObject *)PyArray_SimpleNew(1, &n, PyArray_DOUBLE);#else array = (PyArrayObject *)PyArray_FromDims(1, &n, PyArray_DOUBLE);#endif if (array == NULL) return NULL; d = (double *)array->data; iterator.state = nblist_start; i = 0; while (nblist_iterate(nblist, &iterator)) { nblist->universe_spec->distance_function(dv, nblist->lastx[iterator.a1], nblist->lastx[iterator.a2], nblist->universe_spec->geometry_data); d[i++] = vector_length(dv); } return (PyObject *)array;}
开发者ID:CCBatIIT,项目名称:AlGDock,代码行数:34,
示例20: vector_divide// return true if motion detected.bool motion_detector::new_data(vector v){ if (avg_count <= 0) { accumulated = v; avg_count = 1; return false; } // t = accumulated/avg_count - v vector t = accumulated; vector_divide(&t, avg_count); vector_sub(&t, &v); if (vector_length(&t) > threshold) { accumulated = v; avg_count = 1; return true; } vector_add(&accumulated, &v); avg_count++; return false;}
开发者ID:my12doom,项目名称:pilot2,代码行数:29,
示例21: marshal_arraystatic int marshal_array(json_node *n, buffer *buf) { int retCode; if (n->arr == NULL) { if ((retCode = buffer_append(buf, "null", 4)) > 0) { return retCode; } } else { if ((retCode = buffer_append(buf, "[", 1)) > 0) { return retCode; } size_t len = vector_length(n->arr); for (int i = 0; i < len; ++i) { void *p = NULL; if ((retCode = v_get_ptr(n->arr, i, &p)) > 0) { return retCode; } if ((retCode = marshal_recursive((json_node*)p, buf)) > 0) { return retCode; } if (i < len - 1 && (retCode = buffer_append(buf, ",", 1)) > 0) { return retCode; } } if ((retCode = buffer_append(buf, "]", 1)) > 0) { return retCode; } } return 0;}
开发者ID:mlmhl,项目名称:cWeb,代码行数:32,
示例22: op_lsvoid op_ls(const char **params, int nparams) { assert(nparams > 0); inode_t *ino = vfs_open(params[0], &dummy_access); assert(ino && "File not found!"); vector_t files = vfs_readdir(ino); for (unsigned i = 0; i < vector_length(&files); ++i) { dirent_t *dent = vector_get(&files, i); const char *c; switch (dent->ino->type) { case it_file: c = "FILE"; break; case it_dir: c = "DIR"; break; case it_chardev: c = "CDEV"; break; case it_blockdev: c = "BDEV"; break; case it_fifo: c = "FIFO"; break; case it_socket: c = "SOCK"; break; default: assert(0); } kprintf("[[%s]] %s : nlink %d mode %x ctime %d mtime %d atime %d uid %d gid %d size %d/n", c, dent->name, dent->ino->nlink, dent->ino->mode, dent->ino->ctime, dent->ino->mtime, dent->ino->atime, dent->ino->uid, dent->ino->gid, dent->ino->size); }}
开发者ID:RobinVan,项目名称:JMTK,代码行数:27,
示例23: mainint main(int argc, char *argv[]) { vector a; vector_init(&a, 0); // test for ptr operations int n = 5; for (int i = 0; i < n; ++i) { char *str = malloc(2); v_push_ptr(&a, itoa(i, str, 10)); } vector_print(&a); for (int i = 0; i < n / 2; ++i) { void *p = NULL; v_get_ptr(&a, i, &p); void *q =NULL; v_get_ptr(&a, n - i - 1, &q); v_set_ptr(&a, i, q); v_set_ptr(&a, n - i - 1, p); } vector_print(&a); while (vector_length(&a) > 0) { v_pop_ptr(&a, NULL); } return 0;}
开发者ID:mlmhl,项目名称:cWeb,代码行数:29,
示例24: sphere_intersect/** * sphere_intersect - Check ray intersection with a sphere object. * @sphere: Pointer to sphere object * @ray: Pointer to normalized ray object * * This function will test if a ray, @ray, will intersect a sphere, @sphere. * Imaging a ray R with origin at E and direction V intersecting a sphere with * center O and radius r. The intersection point will be detnoted P. A triangle * E-O-A, where A is a right angle can be drawn. The E-O side has length c, E-A * has length v and O-A has length b. See figure 1. * * ...---o O ...---o O * c ...--- | r ...--- | * ...--- | b ...--- | b * ...--- | ...--- | * E o------------------------o A P o------------------------o A * v d * fig 1. fig 2. * * The v side will then have the same direction as V and i.e. will represent a * bit of the ray R. * Pythagorean theorem gives: * v C++ vector_new函数代码示例 C++ vector_iget_const函数代码示例
|