double PatchyDisc::computePairEnergy(unsigned int particle1, double position1[], double orientation1[], unsigned int particle2, double position2[], double orientation2[]) { // Separation vector. std::vector<double> sep(2); // Calculate disc separation. sep[0] = position1[0] - position2[0]; sep[1] = position1[1] - position2[1]; // Enforce minimum image. box.minimumImage(sep); // Calculate squared norm of vector. double normSqd = sep[0]*sep[0] + sep[1]*sep[1]; // Discs overlap. if (normSqd < 1) return INF; // Total interaction energy sum. double energy = 0; // Test interactions between all patch pairs. for (unsigned int i=0;i<maxInteractions;i++) { // Compute position of patch i on first disc. std::vector<double> coord1(2); coord1[0] = position1[0] + 0.5*(orientation1[0]*cosTheta[i] - orientation1[1]*sinTheta[i]); coord1[1] = position1[1] + 0.5*(orientation1[0]*sinTheta[i] + orientation1[1]*cosTheta[i]); // Enforce periodic boundaries. box.periodicBoundaries(coord1); for (unsigned int j=0;j<maxInteractions;j++) { // Compute position of patch j on second disc. std::vector<double> coord2(2); coord2[0] = position2[0] + 0.5*(orientation2[0]*cosTheta[j] - orientation2[1]*sinTheta[j]); coord2[1] = position2[1] + 0.5*(orientation2[0]*sinTheta[j] + orientation2[1]*cosTheta[j]); // Enforce periodic boundaries. box.periodicBoundaries(coord2); // Calculate patch separation. sep[0] = coord1[0] - coord2[0]; sep[1] = coord1[1] - coord2[1]; // Enforce minimum image. box.minimumImage(sep); // Calculate squared norm of vector. normSqd = sep[0]*sep[0] + sep[1]*sep[1]; // Patches interact. if (normSqd < squaredCutOffDistance) energy -= interactionEnergy; } } return energy; }
double point_distance(const T& point_a, const T& point_b) { double diff_coord1 = coord1(a) - coord1(b); double diff_coord2 = coord2(a) - coord2(b); double distance = hypot(diff_coord1, diff_coord2); return distance; }
void ReviewDialog::updateSkillArea() { for (std::vector<MyGUI::Widget*>::iterator it = mSkillWidgets.begin(); it != mSkillWidgets.end(); ++it) { MyGUI::Gui::getInstance().destroyWidget(*it); } mSkillWidgets.clear(); const int valueSize = 40; MyGUI::IntCoord coord1(10, 0, mSkillView->getWidth() - (10 + valueSize) - 24, 18); MyGUI::IntCoord coord2(coord1.left + coord1.width, coord1.top, valueSize, coord1.height); if (!mMajorSkills.empty()) addSkills(mMajorSkills, "sSkillClassMajor", "Major Skills", coord1, coord2); if (!mMinorSkills.empty()) addSkills(mMinorSkills, "sSkillClassMinor", "Minor Skills", coord1, coord2); if (!mMiscSkills.empty()) addSkills(mMiscSkills, "sSkillClassMisc", "Misc Skills", coord1, coord2); // Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden mSkillView->setVisibleVScroll(false); mSkillView->setCanvasSize (mSkillView->getWidth(), std::max(mSkillView->getHeight(), coord1.top)); mSkillView->setVisibleVScroll(true); }
void forwardDiff(DisplayFile* disp, double x, double y, double z, double delta1X, double delta1Y, double delta1Z, double delta2X, double delta2Y, double delta2Z, double delta3X, double delta3Y, double delta3Z){ double xOld = x; double yOld = y; double zOld = z; for (int i = 0; i < 10; ++i) { cout << "criou retinha" << endl; x += delta1X; delta1X += delta2X; delta2X += delta3X; y += delta1Y; delta1Y += delta2Y; delta2Y += delta3Y; z += delta1Z; delta1Z += delta2Z; delta2Z += delta3Z; Objeto * obj = new Objeto(" ", Reta, false); Coordenada coord1(xOld,yOld,zOld); Coordenada coord2(x,y,z); obj->adiciona(coord1); obj->adiciona(coord2); disp->adiciona(obj); xOld = x; yOld = y; zOld = z; } }
TEST(DestinationPoint, GoStraightNorth) { GeographicCoordinate coord1 (16, 16, 25000); Velocity vel (100, 100, 100); //GeographicCoordinate dest = GenerationMath::DestinationPoint(coord1, vel, 0); //std::cout << "\n" << dest.GetLatitude() << " " << dest.GetLongitude() << std::endl; //ASSERT_NEAR(16.004, dest.GetLatitude(),.005); //ASSERT_NEAR(16.0, dest.GetLongitude(),.005); }
TEST(DistanceBetweenTwoCoordinates, CloseBy) { GeographicCoordinate coord1 (65.2, 145, 25000); GeographicCoordinate coord2 (65.3, 145, 25000); std::cout << GenerationMath::DistanceBetweenTwoCoordinates( coord1, coord2) << std::endl; ASSERT_NEAR(36500.64, GenerationMath::DistanceBetweenTwoCoordinates( coord1, coord2),5); }
TEST(DestinationPoint, GoStraightEast) { GeographicCoordinate coord1 (16, 16, 25000); Velocity vel (100, 100, 100); //GeographicCoordinate dest = GenerationMath::DestinationPoint(coord1, vel, 90); //std::cout << "\n" << dest.GetLatitude() << " " << dest.GetLongitude() << std::endl; //ASSERT_NEAR(16.00, dest.GetLatitude(),.005); //ASSERT_NEAR(16.004, dest.GetLongitude(),.005); //GeographicCoordinate coord2 (123, 24, 345); GeographicCoordinate coord2 (50, 60, 100); GeographicCoordinate final = GenerationMath::DestinationPoint(coord2, Velocity(34, 0, 23), 270); //std::cout << "lat: " << final.GetLatitude() << " long: " << final.GetLongitude() << std::endl; GeographicCoordinate coord3 (89, 131, 345); GeographicCoordinate final2 = GenerationMath::DestinationPoint(coord3, Velocity(34, 0, 23), 270); //std::cout << "\nlat: " << final2.GetLatitude() << " long: " << final2.GetLongitude() << std::endl; }
static void go() { gmtl::Vec<T, 3> p( 1, 2, 3 ); gmtl::EulerAngle<T, gmtl::XYZ> r( 4, 5, 6 ); gmtl::Coord<gmtl::Vec<T,3>, gmtl::EulerAngle<T, gmtl::XYZ> > coord1(p,r), coord2; coord1 = coord2; CPPUNIT_ASSERT( coord1 == coord2 ); CPPUNIT_ASSERT( coord2 == coord1 ); // Test that != works on all elements for (int j = 0; j < 3; ++j) { coord2.pos()[j] = (T)1221.0f; CPPUNIT_ASSERT( (coord1 != coord2) ); CPPUNIT_ASSERT( !(coord1 == coord2) ); coord2.pos()[j] = coord1.pos()[j]; // put it back coord2.rot()[j] = (T)1221.0f; CPPUNIT_ASSERT( (coord1 != coord2) ); CPPUNIT_ASSERT( !(coord1 == coord2) ); coord2.rot()[j] = coord1.rot()[j]; // put it back } // Test for epsilon equals working CPPUNIT_ASSERT( gmtl::isEqual( coord1, coord2 ) ); CPPUNIT_ASSERT( gmtl::isEqual( coord1, coord2, (T)0.0f ) ); CPPUNIT_ASSERT( gmtl::isEqual( coord2, coord1, (T)0.0f ) ); CPPUNIT_ASSERT( gmtl::isEqual( coord2, coord1, (T)100000.0f ) ); T eps = (T)10.0; for (int j = 0; j < 3; ++j) { coord2.pos()[j] = coord1.pos()[j] - (eps / (T)2.0); CPPUNIT_ASSERT( gmtl::isEqual( coord1, coord2, eps ) ); CPPUNIT_ASSERT( !gmtl::isEqual( coord1, coord2, (T)(eps / 3.0) ) ); coord2.pos()[j] = coord1.pos()[j]; // put it back coord2.rot()[j] = coord1.rot()[j] - (eps / (T)2.0); CPPUNIT_ASSERT( gmtl::isEqual( coord1, coord2, eps ) ); CPPUNIT_ASSERT( !gmtl::isEqual( coord1, coord2, (T)(eps / 3.0) ) ); coord2.rot()[j] = coord1.rot()[j]; // put it back } }
void RaceDialog::updateSkills() { for (std::vector<MyGUI::Widget*>::iterator it = mSkillItems.begin(); it != mSkillItems.end(); ++it) { MyGUI::Gui::getInstance().destroyWidget(*it); } mSkillItems.clear(); if (mCurrentRaceId.empty()) return; Widgets::MWSkillPtr skillWidget; const int lineHeight = 18; MyGUI::IntCoord coord1(0, 0, mSkillList->getWidth(), 18); const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore(); const ESM::Race *race = store.get<ESM::Race>().find(mCurrentRaceId); int count = sizeof(race->mData.mBonus)/sizeof(race->mData.mBonus[0]); // TODO: Find a portable macro for this ARRAYSIZE? for (int i = 0; i < count; ++i) { int skillId = race->mData.mBonus[i].mSkill; if (skillId < 0 || skillId > ESM::Skill::Length) // Skip unknown skill indexes continue; skillWidget = mSkillList->createWidget<Widgets::MWSkill>("MW_StatNameValue", coord1, MyGUI::Align::Default, std::string("Skill") + boost::lexical_cast<std::string>(i)); skillWidget->setSkillNumber(skillId); skillWidget->setSkillValue(Widgets::MWSkill::SkillValue(race->mData.mBonus[i].mBonus)); ToolTips::createSkillToolTip(skillWidget, skillId); mSkillItems.push_back(skillWidget); coord1.top += lineHeight; } }
/* ================================================================================================= */ void Graph::color_standard_weights(const multi_img & image, SimMeasure *distfun, bool geodesic) { /* ================================================================================================== */ /* Computes weights inversely proportional to the image gradient for 2D images */ bool gray = (image.size() == 1); // make sure we don't run into cache misses if (!gray) image.rebuildPixels(); const multi_img::Band& band0 = image[0]; if (gray) { max_weight = 255.f; // we will never adjust it } else { max_weight = 0.f; } // import edge coloring from image for (unsigned int i = 0; i < edges.size(); i++) { // hackish! rewrite edges code! width == number of columns cv::Point coord1(edges[i].nodes[0] % width, edges[i].nodes[0] / width), coord2(edges[i].nodes[1] % width, edges[i].nodes[1] / width); if (gray) { edges[i].weight = std::abs(band0(coord1) - band0(coord2)); } else { const multi_img::Pixel &p1 = image(coord1), &p2 = image(coord2); edges[i].weight = (float)distfun->getSimilarity(p1, p2, coord1, coord2); max_weight = std::max<float>(edges[i].weight, max_weight); } } bucketsize = max_weight / 250.f; // TODO: make this user-selectable if (!geodesic) { for (unsigned int i = 0; i < edges.size(); i++) edges[i].weight = max_weight - edges[i].weight; /* RESULT: edges[].weight: regular weights (maxw - X) edges[].norm_weight: unset */ return; } for (unsigned int i = 0; i < edges.size(); i++) edges[i].norm_weight = max_weight - edges[i].weight; /* fill in initial weights for edges originating from seeds */ float *seeds_function = (float*)calloc(edges.size(), sizeof(float)); for (unsigned int j = 0; j < seeds.size(); j++) { for (int k = 1; k <= degree; k++) { int n = neighbor_node_edge(seeds[j].first, k); if (n != -1) seeds_function[n] = edges[n].norm_weight; } } gageodilate_union_find(seeds_function); free(seeds_function); /* RESULT: edges[].weight: reconstructed weights edges[].norm_weight: regular weights (maxw - X) */ }
void TextureBackground::updateGrid(void) { bool gridChanged=( (getHor() != _hor) || (getVert() != _vert) ); if(gridChanged) { //resize grid UInt32 gridCoords=(getHor()+2)*(getVert()+2); _textureCoordArray.resize(gridCoords); _vertexCoordArray .resize(gridCoords); int indexArraySize=(getHor()+2)*((getVert()+1)*2); _indexArray.resize(indexArraySize); _hor = getHor(); _vert = getVert(); } if(gridChanged || _radialDistortion != getRadialDistortion() || _centerOfDistortion != getCenterOfDistortion() ) { _radialDistortion = getRadialDistortion(); _centerOfDistortion = getCenterOfDistortion(); // calculate grid coordinates and triangle strip indices float xStep=1.0/float(getHor()+1); float yStep=1.0/float(getVert()+1); std::vector<Vec2f>::iterator texCoord=_textureCoordArray.begin(); std::vector<Vec2f>::iterator vertexCoord=_vertexCoordArray.begin(); std::vector<UInt32>::iterator index=_indexArray.begin(); UInt32 coord0(0),coord1(0); GLfloat x,y; Int16 xx,yy; Int16 xxmax=getHor()+2,yymax=getVert()+2; for(yy=0,y=0.0f;yy<yymax;yy++,y+=yStep) { if(yy>0) { coord1=yy*xxmax; coord0=coord1-xxmax; *index++=coord1++; *index++=coord0++; } float dy=y-getCenterOfDistortion().y(); float dy2=dy*dy; for(xx=0,x=0.0f;xx<xxmax;xx++,x+=xStep) { *texCoord++=Vec2f(x,y); float dx=(x-getCenterOfDistortion().x()); float dx2=dx*dx; float dist2=dx2+dy2; float deltaX=dx*getRadialDistortion()*dist2; float deltaY=dy*getRadialDistortion()*dist2; *vertexCoord++=Vec2f(x+deltaX,y+deltaY); if(yy>0&&xx>0) { *index++=coord1++; *index++=coord0++; } } } } }
TEST(AbsoluteBearingBetweenTwoCoordinates, BiggerNumbers) { GeographicCoordinate coord1 (2, 67, 25000); GeographicCoordinate coord2 (45, 78, 25000); ASSERT_NEAR(11.18329583708925, GenerationMath::AbsoluteBearingBetweenTwoCoordinates( coord1, coord2),.001); }
TEST(AbsoluteBearingBetweenTwoCoordinates, SameLatitude) { GeographicCoordinate coord1 (16, 16, 25000); GeographicCoordinate coord2 (12, 12, 25000); ASSERT_NEAR(224.63804446443481, GenerationMath::AbsoluteBearingBetweenTwoCoordinates( coord1, coord2),.001); }
TEST(DistanceBetweenTwoCoordinates, SamePoint) { GeographicCoordinate coord1 (65, 145, 25000); GeographicCoordinate coord2 (65, 145, 25000); ASSERT_NEAR(0, GenerationMath::DistanceBetweenTwoCoordinates( coord1, coord2),.00000001); }