this is what I understood of your scenario
you have one polymer which is composed by monomers
a monomer is a rectangular prism, it knows its dimensions {length, width, height}, ¿does it know its position {x,yz}? (of the mass center)
you one to add another monomer to the polymer so you create a random rotation (¿no translation?)
if it intersects the polymer, the insertion fails, so you generate another rotation.
now, your code
in `Polymer::position()' you have
Quaternion<float> fpos(0.0f, 0.5f + _origin_x, 0.5f + _origin_y, _origin_z)
¿why the 0.5 offset? ¿why only on x and y and not in z?
it seems that this calculates the position of each monomer in the polymer
you move m[i].h in direction d[i] ¿does this give you the center of the monomer?
but then the distance between m[i].center and m[i-1].center will only be m[i].h, ¿shouldn't be (m[i].h + m[i-1].h)/2?
in `Polymer::intersecting()' there are a lot of things happening, I'll suggest you to explode that function
first, you get the position of the last monomer on the chain, and you add the new candidate but here you move only m.h/2, ¿why only half?
(you do this exact same computation for each iteration of the loop)
then you calculate the position of m[i], and move it according to its rotation ipos+rpos (¿?)
don't understand, ¿position() don't give you the position? ¿you need another offset?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
//let's say that each monomer knows the position of its center
bool
intersecting(const Monomer& a, const Monomer& b){ //note, no mention of polymer
auto distance = a.center - b.center;
return norm2(distance) < a.getSphereRadius()+b.getSphereRadius();
}
bool
Polymer::add(Monomer monomer, const Quaternion<float> &rotation)
{
double d = (monomer.height() + _monomers.back().height()) / 2;
vector offset = rotation*d*conj(rotation);
monomer.center = _monomers.back().center + offset;
for (int32_t i = 0; i < (number_of_monomers()-1); i++)
{
if (intersecting(monomer, _monomers[i])) return false; //failure
}
_monomers.push_back(monomer);
_rotations.push_back(rotation);
return true;
}
| |
for testing, make all the monomers cubes of the same size
paint different the last inserted and candidate
and perhaps limit to the plane {x,y} (no movement on z)
> it gets in the infinity loop, meaning that no possible cuboid can be
> generated which would not intersect with previous - which is nonsense
¿why is nonsense? if the chain folded on itself (like a spiral) you may have no space to continue