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(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; }
/* ================================================================================================= */ 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 WorldViewWindow::updateViewportAbsCoord() { MyGUI::IntCoord coord = mCanvas->getAbsoluteCoord(); ViewportAbsCoord coord2(coord.left, coord.top, coord.width, coord.height); mWorld->setViewportAbsCoord(coord2); }
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); }