qt - QTransform: How to iteratively map composition of transformation matrices to object? -
qt - QTransform: How to iteratively map composition of transformation matrices to object? -
i've tried everything, still have no thought how map composition of 3 transformation matrices line iteratively first 2 iterations of koch curve.
let me explain problem. i've got 3 input parameters:
base object (this object stored in list "0. iteration") list of transformation matrices (every matrix can composed more basic matrices of scaling, rotation , translation) iteration numbernow algorithm should following:
initialize empty list of new objects - size of list count of transformation matrices multiplied count of list of objects previous iteration loop through matrices map current matrix base of operations object store transformed object in list after end of loop list of new objects become current iteration. goto 1. until required iteration number achievedlet's take illustration koch curve - first 3 iterations:
parameters:
base object = line matrices = 1: scale 1 third; 2: scale 1 third, rotate 60 degrees, move 1 third; 3: scale 1 third, rotate 120 degrees, move 2 thirds; 4: scale 1 third, move 1 iteration number = 2and code. i've tried several changes of code, nil worked :-(. have following:
let's assume, that:
this->currentiterationnumber = 1
ifsfractal::iteration* ifsfractal::nextiteration() { // if next iteration computed, homecoming if ((this->currentiterationnumber + 1) < this->iterations.size()) { homecoming this->iterations.at(++this->currentiterationnumber); } // compute next iteration else { ifsfractal::iteration *nextiteration = new ifsfractal::iteration(); ifsfractal::iteration *currentiteration = this->iterations.at(this->currentiterationnumber); qlist<qtransform> newiterationmatrices; // there much new shapes count of matrices qint32 = 0; qlistiterator<qpolygonf*> iterator(currentiteration->iteration); while (iterator.hasnext()) { qpolygonf currentshape = *iterator.next(); qpointf currentposition = currentshape.at(0); // lastly computed matrix (here stored lastly rotation, scale, ...) qtransform lastmatrix = this->lastiterationmatrices.at(i++); // move current shape origin of coordinate scheme qtransform toorigin; toorigin.translate(-currentposition.x(), -currentposition.y()); currentshape = toorigin.map(currentshape); // go through matrices qlistiterator<qtransform> matrixiterator(this->matrices); while (matrixiterator.hasnext()) { qtransform currentmatrix = lastmatrix * matrixiterator.next(); newiterationmatrices.append(currentmatrix); // map transformation qpolygonf newshape = currentmatrix.map(currentshape); // returns new shape right position qtransform toposition; toposition.translate(currentposition.x(), currentposition.y()); newshape = toposition.map(newshape); // save transformed shape pointer qpolygonf *p_newshape = new qpolygonf(newshape); nextiteration->iteration.append(p_newshape); } } this->lastiterationmatrices = newiterationmatrices; this->currentiterationnumber++; this->iterations.append(nextiteration); homecoming nextiteration; } }
and here qtransforms:
// line segment qpolygonf *line = new qpolygonf(); line->append(qpointf(0, 0.75)); line->append(qpointf(1, 0.75)); // 0. iteration ifsfractal::iteration *zero = new ifsfractal::iteration(); zero->iteration.append(line); // save 0. iteration this->iterations.append(zero); // transform matrices // scaling 1 3rd qtransform transform1; transform1.scale(1.0 / 3, 1.0 / 3); this->addmatrix(1, transform1); // scaling 1/3, translation , rotation 60 deg qtransform transform2; transform2.scale(1.0 / 3, 1.0 / 3) .translate(1, 0) .rotate(-60); this->addmatrix(2, transform2); // scaling 1/3, translation , rotation 120 deg qtransform transform3; transform3.scale(1.0 / 3, 1.0 / 3) .translate(2, 0) .rotate(-120); this->addmatrix(3, transform3); // scaling 1/3 , translation right qtransform transform4; transform4.scale(1.0 / 3, 1.0 / 3) .translate(2, 0); this->addmatrix(4, transform4);
but works first iteration , have no thought write correct.
my result:
help me please, i'm little bit desperate :-(.
thank very much.
qt transform fractals
Comments
Post a Comment