本文整理汇总了C++中vector3d::normsquared方法的典型用法代码示例。如果您正苦于以下问题:C++ vector3d::normsquared方法的具体用法?C++ vector3d::normsquared怎么用?C++ vector3d::normsquared使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector3d
的用法示例。
在下文中一共展示了vector3d::normsquared方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: overlap
bool overlap(const polyhedron &a, const polyhedron &b, const double periodic[3], double dr) {
const vector3d ab = periodic_diff(a.pos, b.pos, periodic);
if (ab.normsquared() > sqr(a.R + b.R + 2*dr))
return false;
// construct axes from a
// project a and b to each axis
for (int i=0; i<a.mypoly->nfaces; i++) {
const vector3d axis = a.rot.rotate_vector(a.mypoly->faces[i]);
double projection = axis.dot(a.rot.rotate_vector((a.mypoly->vertices[0])*(a.R+dr)));
double mina = projection, maxa = projection;
for (int j=1; j<a.mypoly->nvertices; j++) {
projection = axis.dot(a.rot.rotate_vector(a.mypoly->vertices[j]*(a.R+dr)));
if (projection < mina) mina = projection;
else if (projection > maxa) maxa = projection;
}
projection = axis.dot(b.rot.rotate_vector(b.mypoly->vertices[0]*(b.R+dr)) + ab);
double minb = projection, maxb = projection;
for (int j=1; j<b.mypoly->nvertices; j++) {
projection = axis.dot(b.rot.rotate_vector(b.mypoly->vertices[j]*(b.R+dr)) + ab);
if (projection < minb) minb = projection;
else if (projection > maxb) maxb = projection;
}
if (mina > maxb || minb > maxa) {
return false;
}
}
// construct axes from b
// project a and b to each axis
for (int i=0; i<b.mypoly->nfaces; i++) {
const vector3d axis = b.rot.rotate_vector(b.mypoly->faces[i]);
double projection = axis.dot(a.rot.rotate_vector(a.mypoly->vertices[0]*(a.R+dr)));
double mina = projection, maxa = projection;
for (int j=1; j<a.mypoly->nvertices; j++) {
projection = axis.dot(a.rot.rotate_vector(a.mypoly->vertices[j]*(a.R+dr)));
if (projection < mina) mina = projection;
else if (projection > maxa) maxa = projection;
}
projection = axis.dot(b.rot.rotate_vector(b.mypoly->vertices[0]*(b.R+dr)) + ab);
double minb = projection, maxb = projection;
for (int j=1; j<b.mypoly->nvertices; j++) {
projection = axis.dot(b.rot.rotate_vector(b.mypoly->vertices[j]*(b.R+dr)) + ab);
if (projection < minb) minb = projection;
else if (projection > maxb) maxb = projection;
}
if (mina > maxb || minb > maxa) {
return false;
}
}
return true;
}
示例2: overlap_in_small_cell
static bool overlap_in_small_cell(sw_simulation &sw, double scaling_factor){
double scaled_len[3];
for(int i=0; i < 3; i++){
scaled_len[i] = scaling_factor * sw.len[i];
}
for(int i=0; i<sw.N; i++){
for (int j=i+1; j<sw.N; j++) {
// copy pasting from overlap() in square-well.cpp for now
// contemplated adding a scaling parametor to overlap(), but decided on this for now.
const vector3d ab = periodic_diff(scaling_factor * sw.balls[i].pos, scaling_factor * sw.balls[j].pos,
scaled_len, sw.walls);
if (ab.normsquared() < sqr(sw.balls[i].R + sw.balls[j].R)) {
return true;
}
}
}
return false;
}
示例3: overlaps_with_any
int overlaps_with_any(const polyhedron &a, const polyhedron *bs,
const double periodic[3], bool count, double dr) {
// construct axes from a and a's projection onto them
vector3d *aaxes = new vector3d[a.mypoly->nfaces];
double amins[a.mypoly->nfaces], amaxes[a.mypoly->nfaces];
for (int i=0; i<a.mypoly->nfaces; i++) {
aaxes[i] = a.rot.rotate_vector(a.mypoly->faces[i]);
double projection = aaxes[i].dot(a.rot.rotate_vector(a.mypoly->vertices[0]*(a.R+dr)));
amins[i] = projection, amaxes[i] = projection;
for (int j=1; j< a.mypoly->nvertices; j++) {
projection = aaxes[i].dot(a.rot.rotate_vector(a.mypoly->vertices[j]*(a.R+dr)));
amins[i] = min(projection, amins[i]);
amaxes[i] = max(projection, amaxes[i]);
}
}
int num_overlaps = 0;
for (int l=0; l<a.num_neighbors; l++) {
const int k = a.neighbors[l];
const vector3d ab = periodic_diff(a.pos, bs[k].pos, periodic);
if (ab.normsquared() < sqr(a.R + bs[k].R + 2*dr)) {
bool overlap = true; // assume overlap until we prove otherwise or fail to.
// check projection of b against a's axes
for (int i=0; i<a.mypoly->nfaces; i++) {
double projection = aaxes[i].dot
(bs[k].rot.rotate_vector(bs[k].mypoly->vertices[0]*(bs[k].R+dr)) + ab);
double bmin = projection, bmax = projection;
for (int j=1; j<bs[k].mypoly->nvertices; j++) {
projection = aaxes[i].dot
(bs[k].rot.rotate_vector(bs[k].mypoly->vertices[j]*(bs[k].R+dr)) + ab);
bmin = min(projection, bmin);
bmax = max(projection, bmax);
}
if (amins[i] > bmax || bmin > amaxes[i]) {
overlap = false;
i = a.mypoly->nfaces; // no overlap, move on to next
}
}
if (overlap) { // still need to check against b's axes
for (int i=0; i<bs[k].mypoly->nfaces; i++) {
const vector3d axis = bs[k].rot.rotate_vector(bs[k].mypoly->faces[i]);
double projection = axis.dot(a.rot.rotate_vector(a.mypoly->vertices[0]*(a.R+dr)));
double amin = projection, amax = projection;
for (int j=1; j<a.mypoly->nvertices; j++) {
projection = axis.dot(a.rot.rotate_vector(a.mypoly->vertices[j]*(a.R+dr)));
amin = min(projection, amin);
amax = max(projection, amax);
}
projection = axis.dot
(bs[k].rot.rotate_vector(bs[k].mypoly->vertices[0]*(bs[k].R+dr)) + ab);
double bmin = projection, bmax = projection;
for (int j=1; j<bs[k].mypoly->nvertices; j++) {
projection = axis.dot
(bs[k].rot.rotate_vector(bs[k].mypoly->vertices[j]*(bs[k].R+dr)) + ab);
bmin = min(projection, bmin);
bmax = max(projection, bmax);
}
if (amin > bmax || bmin > amax) {
overlap = false;
i = bs[k].mypoly->nfaces; //no overlap, move on to next
}
}
}
if (overlap) {
if(!count) {
delete[] aaxes;
return 1;
}
num_overlaps ++;
}
}
}
delete[] aaxes;
return num_overlaps;
}