// // re-calculate frequency response // void Plot::setDamp( double damping ) { const bool doReplot = autoReplot(); setAutoReplot( false ); const int ArraySize = 200; double frequency[ArraySize]; double amplitude[ArraySize]; double phase[ArraySize]; // build frequency vector with logarithmic division logSpace( frequency, ArraySize, 0.01, 100 ); int i3 = 1; double fmax = 1; double amax = -1000.0; for ( int i = 0; i < ArraySize; i++ ) { double f = frequency[i]; const ComplexNumber g = ComplexNumber( 1.0 ) / ComplexNumber( 1.0 - f * f, 2.0 * damping * f ); amplitude[i] = 20.0 * log10( qSqrt( g.real() * g.real() + g.imag() * g.imag() ) ); phase[i] = qAtan2( g.imag(), g.real() ) * ( 180.0 / M_PI ); if ( ( i3 <= 1 ) && ( amplitude[i] < -3.0 ) ) i3 = i; if ( amplitude[i] > amax ) { amax = amplitude[i]; fmax = frequency[i]; } } double f3 = frequency[i3] - ( frequency[i3] - frequency[i3 - 1] ) / ( amplitude[i3] - amplitude[i3 -1] ) * ( amplitude[i3] + 3 ); showPeak( fmax, amax ); show3dB( f3 ); showData( frequency, amplitude, phase, ArraySize ); setAutoReplot( doReplot ); replot(); }
ComplexNumber ComplexNumber::operator*(const ComplexNumber& z) const { return ComplexNumber(mRealPart * z.GetRealPart() - mImaginaryPart * z.GetImaginaryPart(), mImaginaryPart * z.GetRealPart() + mRealPart * z.GetImaginaryPart()); }
FORCEINLINE ComplexNumber CmpSphericalHarmonic( int nL, int nM, float flTheta, float flPhi, float flCosTheta ) { if ( nM == 0 ) return SHNormalizationFactor( nL, 0 ) * AssociatedLegendrePolynomial( nL, nM, flCosTheta ); return SQRT_2 * SHNormalizationFactor( nL, -nM ) * ComplexNumber(1.0f, nM * flPhi, true) /*e^(i*m*phi)*/ * AssociatedLegendrePolynomial( nL, -nM, flCosTheta ); }
void drawMandelbrot(QImage & image, int iterations, QVector2D offset, double size, ComplexNumber critical) { ComplexNumber fz, c; double rx, ry; float color = 0.0; int wx = image.width(), wy = image.height(); int byteOffset = image.bytesPerLine() / image.width(); #pragma omp parallel for ordered schedule(dynamic) for(int y = 0; y < wy; ++y) { uchar *scanline = image.scanLine(y); for(int x = 0; x < wx; x++) { rx = (2.0 * ((double)x / (double)wx) - 1.0); ry = (2.0 * ((double)y / (double)wy) - 1.0); c = ComplexNumber(rx * size + offset.x(), ry * size + offset.y()); fz = critical; //qDebug() << "x: " << z << ", y: " << c; //fz = mandelbrot(fz, c); int i = 0; for(i = 0; i < iterations && abs(fz) <= 2.0; ++i) { fz = mandelbrot(fz, c); } #pragma omp ordered { color = (float)i / (float)iterations; if(image.format() == QImage::Format_RGB888) { *(scanline + x * byteOffset) = 255 * color; *(scanline + x * byteOffset + 1) = 255 * color; *(scanline + x * byteOffset + 2) = 255 * color; } if(image.format() == QImage::Format_Indexed8) { *(scanline + x * byteOffset) = i % (image.colorCount() + 1);// * color; } } //image.setPixel(x, y, qRgb(i % 256, i % 256, i % 256)); //image.setPixel(x, y, i % 256); } } }
int main(int argc, char* argv[]) { std::vector<ComplexNumber> numbers; numbers.reserve(6); numbers.push_back(ComplexNumber(1.0, 2.0)); numbers.push_back(ComplexNumber(2.0, -1.0)); numbers.push_back(ComplexNumber(0.0, 0.0)); std::cout << "Length of vector is " << numbers.size() << "\n"; std::cout << "Entries of vector are\n"; for (int i=0; i<3; i++) { std::cout << numbers[i] << "\n"; } std::vector<ComplexNumber>::const_iterator c; for (c=numbers.begin(); c!=numbers.end(); c++) { std::cout << *c << "\n"; } numbers.insert(numbers.begin(), ComplexNumber(5.0, 5.0)); numbers.insert(numbers.begin()+1, ComplexNumber(-1.1, -2.0)); numbers.push_back(ComplexNumber(0.0, -2.0)); std::cout << "Length of vector is " << numbers.size() << "\n"; std::cout << "Entries of vector are\n"; for (c=numbers.begin(); c!=numbers.end(); c++) { std::cout << *c << "\n"; } numbers.erase(numbers.begin()+3, numbers.end()); std::cout << "Length of vector is " << numbers.size() << "\n"; std::cout << "Entries of vector are\n"; for (c=numbers.begin(); c!=numbers.end(); c++) { std::cout << *c << "\n"; } std::sort(numbers.begin(), numbers.end()); std::cout << "Length of vector is " << numbers.size() << "\n"; std::cout << "Entries of vector are\n"; for (c=numbers.begin(); c!=numbers.end(); c++) { std::cout << *c << "\n"; } return 0; }
// Computes the complex conjugate ComplexNumber ComplexNumber::CalculateConjugate() const { return ComplexNumber(mRealPart, -mImaginaryPart); }
bool SceneParser::addQuadric(struct basicxmlnode * elementNode, Scene * scene) { if (!elementNode) { std::cout << "SceneParser::addQuadric: empty node \n"; return false; } if (std::string(elementNode->tag) != "Quadric") { return false; } // create quadric Quadric * quadric = new Quadric(scene->getDefaultMaterial()); Vector3 center; double a_real, a_img, b_real, b_img, c_real, c_img; double reflectionPercentage; double refractionIndex; double refractionPercentage; Vector4 color; // read user specified values char * attributeValue1, * attributeValue2; if (attributeValue1 = getattributevaluebyname(elementNode, "center")) { if (!stringToVector3<double>(center, attributeValue1)) { delete(quadric); return false; } quadric->setCenter(center); } if ( (attributeValue1 = getattributevaluebyname(elementNode, "aReal")) && (attributeValue2 = getattributevaluebyname(elementNode, "aImg")) ) { if (!stringToNumber<double>(a_real, attributeValue1) || !stringToNumber<double>(a_img, attributeValue2)) { delete(quadric); return false; } quadric->setA(ComplexNumber(a_real,a_img)); } if ( (attributeValue1 = getattributevaluebyname(elementNode, "bReal")) && (attributeValue2 = getattributevaluebyname(elementNode, "bImg")) ) { if (!stringToNumber<double>(b_real, attributeValue1) || !stringToNumber<double>(b_img, attributeValue2)) { delete(quadric); return false; } quadric->setB(ComplexNumber(b_real,b_img)); } if ( (attributeValue1 = getattributevaluebyname(elementNode, "cReal")) && (attributeValue2 = getattributevaluebyname(elementNode, "cImg")) ) { if (!stringToNumber<double>(c_real, attributeValue1) || !stringToNumber<double>(c_img, attributeValue2)) { delete(quadric); return false; } quadric->setC(ComplexNumber(c_real,c_img)); } if (attributeValue1 = getattributevaluebyname(elementNode, "color")) { if (!stringToVector4<double>(color, attributeValue1)) { delete(quadric); return false; } quadric->setColor(color); } if (attributeValue1 = getattributevaluebyname(elementNode, "reflectionPercentage")) { if (!stringToNumber<double>(reflectionPercentage, attributeValue1)) { delete(quadric); return false; } quadric->setReflectionPercentage(reflectionPercentage); } if ( attributeValue1 = getattributevaluebyname(elementNode, "refractionIndex") ) { if ( !stringToNumber<double>(refractionIndex, attributeValue1) ) { delete(quadric); return false; } quadric->setRefractionIndex(refractionIndex); } if ( attributeValue1 = getattributevaluebyname(elementNode, "refractionPercentage") ) { if ( !stringToNumber<double>(refractionPercentage, attributeValue1) ) { delete(quadric); return false; } quadric->setRefractionPercentage(refractionPercentage); } // read material struct basicxmlnode * materialNode = getchildnodebyname(elementNode, "Material"); Material* material = getMaterialReference(materialNode, scene); quadric->setMaterial(material); // add it to scene scene->addElement(quadric); std::cout << "SceneParser::addQuadric: added Quadric\n"; return true; }
ComplexNumber& operator-(ComplexNumber& one, ComplexNumber& two) { return ComplexNumber(one.value.real - two.value.real, one.value.imaginary - two.value.imaginary); }
ComplexNumber operator+(const ComplexNumber& c1, const ComplexNumber& c2){ return ComplexNumber(c1) +=c2; }
ComplexNumber operator-(const ComplexNumber& c1){ return ComplexNumber(-c1.mReal,-c1.mImag); }
ComplexNumber operator+(const ComplexNumber& c1){ return ComplexNumber (c1.Real(),c1.Imag()); }