void AI::updateSteer(AI_Car *c) { c->steerlook.clear(); const BEZIER *curr_patch_ptr = GetCurrentPatch(c->car); //if car has no contact with track, just let it roll if (!curr_patch_ptr) { if (!c->last_patch) return; //if car is off track, steer the car towards the last patch it was on //this should get the car back on track else curr_patch_ptr = c->last_patch; } c->last_patch = curr_patch_ptr; //store the last patch car was on BEZIER curr_patch = RevisePatch(curr_patch_ptr, c->use_racingline); #ifdef VISUALIZE_AI_DEBUG c->steerlook.push_back(curr_patch); #endif //if there is no next patch (probably a non-closed track), let it roll if (!curr_patch.next_patch) return; BEZIER next_patch = RevisePatch(curr_patch.next_patch, c->use_racingline); //find the point to steer towards float track_width = GetPatchWidthVector(curr_patch).Magnitude(); float lookahead = track_width * LOOKAHEAD_FACTOR1 + c->car->GetVelocity().Magnitude() * LOOKAHEAD_FACTOR2; lookahead = 1.0; float length = 0.0; MATHVECTOR <float, 3> dest_point = GetPatchFrontCenter(next_patch); while (length < lookahead) { #ifdef VISUALIZE_AI_DEBUG c->steerlook.push_back(next_patch); #endif length += GetPatchDirection(next_patch).Magnitude()*2.0; dest_point = GetPatchFrontCenter(next_patch); //if there is no next patch for whatever reason, stop lookahead if (!next_patch.next_patch) { length = lookahead; break; } next_patch = RevisePatch(next_patch.next_patch, c->use_racingline); //if next patch is a very sharp corner, stop lookahead if (GetPatchRadius(next_patch) < LOOKAHEAD_MIN_RADIUS) { length = lookahead; break; } } MATHVECTOR <float, 3> next_position = TransformToWorldspace(dest_point); MATHVECTOR <float, 3> car_position = c->car->GetCenterOfMassPosition(); MATHVECTOR <float, 3> car_orientation = direction::Forward; (c->car->GetOrientation()).RotateVector(car_orientation); MATHVECTOR <float, 3> desire_orientation = next_position - car_position; //car's direction on the horizontal plane car_orientation[2] = 0; //desired direction on the horizontal plane desire_orientation[2] = 0; car_orientation = car_orientation.Normalize(); desire_orientation = desire_orientation.Normalize(); //the angle between car's direction and unit y vector (forward direction) double alpha = Angle(car_orientation[0], car_orientation[1]); //the angle between desired direction and unit y vector (forward direction) double beta = Angle(desire_orientation[0], desire_orientation[1]); //calculate steering angle and direction double angle = beta - alpha; //angle += steerAwayFromOthers(c, dt, othercars, angle); //sum in traffic avoidance bias if (angle > -360.0 && angle <= -180.0) angle = -(360.0 + angle); else if (angle > -180.0 && angle <= 0.0) angle = - angle; else if (angle > 0.0 && angle <= 180.0) angle = - angle; else if (angle > 180.0 && angle <= 360.0) angle = 360.0 - angle; float optimum_range = c->car->GetOptimumSteeringAngle(); angle = clamp(angle, -optimum_range, optimum_range); float steer_value = angle / c->car->GetMaxSteeringAngle(); if (steer_value > 1.0) steer_value = 1.0; else if (steer_value < -1.0) steer_value = -1.0; assert(!isnan(steer_value)); c->inputs[CARINPUT::STEER_RIGHT] = steer_value; }
double ON_AngularDimension::NumericValue() { return Angle() * 180.0 / ON_PI; }
bool PlaneGeometry::IsParallel( const PlaneGeometry *plane ) const { return ( (Angle(plane) < 10.0 * mitk::sqrteps ) || ( Angle(plane) > ( vnl_math::pi - 10.0 * sqrteps ) ) ) ; }
// ----------------------------------------------------------------------------- Angle Angle::operator -() const { return Angle(-this->mRadian); }
// ----------------------------------------------------------------------------- Angle Angle::operator - ( const Angle& angle) const { return Angle(*this) -= angle; }
Angle Angle::fromRadians(float radians) { return Angle(Common::rad2deg(radians)); }
// ----------------------------------------------------------------------------- Angle Angle::FromRadians(const float radians) { return Angle(radians); }
BIT_API Angle Radians( const Float64 & p_Radians ) { return Angle( p_Radians ); }
anArrowAspect->SetLength (myArrowLength); gp_Pnt aLastPoint = myPnt; aLastPoint.Translate (myLength*gp_Vec(myDir)); // Draw Line Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments (2); aPrims->AddVertex (myPnt); aPrims->AddVertex (aLastPoint); Prs3d_Root::CurrentGroup (aPresentation)->SetPrimitivesAspect (myDrawer->LineAspect()->Aspect()); Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (aPrims); // Draw arrow Prs3d_Arrow::Draw (aPresentation, aLastPoint, myDir, anArrowAspect->Angle(), anArrowAspect->Length()); // Draw text if (myText.Length() != 0) { gp_Pnt aTextPosition = aLastPoint; Prs3d_Text::Draw (aPresentation, myDrawer->TextAspect(), myText, aTextPosition); } } void ISession_Direction::Compute (const Handle(Prs3d_Projector)& /*aProjector*/,
BodyDescription::BodyDescription(const PhysicsContext &pc, const std::string &resource_id, const XMLResourceDocument &resources) : impl(new BodyDescription_Impl(pc.impl->get_owner())) { /* example resource entry with all parameters: <body2d name="TestBody" type="static"> <position x="0" y="0"/> <rotation angle="180"/> <velocity x="0" y="0" angular="0"/> <damping linear="0" angular="0"/> <parameters awake="true" can_sleep="true" bullet="false" active="true" /> </body2d> */ XMLResourceNode resource = resources.get_resource(resource_id); if (resource.get_type() != "body2d" && resource.get_type() != "body2d_description") throw Exception(string_format("Resource '%1' is not of type 'body2d' or 'body2d_description'", resource_id)); DomNode cur_node = resource.get_element().get_first_child(); //Body type std::string body_type = resource.get_element().get_attribute("type","static"); if(body_type == "kinematic") set_type(body_kinematic); else if(body_type == "dynamic") set_type(body_dynamic); else set_type(body_static); while(!cur_node.is_null()) { if (!cur_node.is_element()) continue; DomElement cur_element = cur_node.to_element(); std::string tag_name = cur_element.get_tag_name(); //<position x="0" y="0"/> if(tag_name == "position") { float pos_x = 0.0f; float pos_y = 0.0f; if(cur_element.has_attribute("x")) { pos_x = StringHelp::text_to_float(cur_element.get_attribute("x")); } if(cur_element.has_attribute("y")) { pos_y = StringHelp::text_to_float(cur_element.get_attribute("y")); } set_position(pos_x, pos_y); } //<rotation angle="180"/> else if(tag_name == "rotation") { Angle angle(0.0f, angle_degrees); if(cur_element.has_attribute("angle")) { angle = Angle(StringHelp::text_to_float(cur_element.get_attribute("angle")), angle_degrees); } set_angle(angle); } //<velocity x="0" y="0" angular="0"/> else if(tag_name == "velocity") { Vec2f velocity(0.0f, 0.0f); Angle angular_velocity(0.0f, angle_degrees); if(cur_element.has_attribute("x")) { velocity.x = StringHelp::text_to_float(cur_element.get_attribute("x")); } if(cur_element.has_attribute("y")) { velocity.y = StringHelp::text_to_float(cur_element.get_attribute("y")); } if(cur_element.has_attribute("angular")) { angular_velocity = Angle(StringHelp::text_to_float(cur_element.get_attribute("angular")), angle_degrees); } set_linear_velocity(velocity); set_angular_velocity(angular_velocity); } //<damping linear="0" angular="0"/> else if(tag_name == "damping") { float linear; float angular; if(cur_element.has_attribute("linear")) { linear = StringHelp::text_to_float(cur_element.get_attribute("linear")); } if(cur_element.has_attribute("angular")) { angular = StringHelp::text_to_float(cur_element.get_attribute("angular")); } set_linear_damping(linear); set_angular_damping(angular); } //<parameters awake="true" can_sleep="true" bullet="false" active="true" /> else if(tag_name == "parameters") { bool value; if(cur_element.has_attribute("awake")) { value = true; value = StringHelp::text_to_bool(cur_element.get_attribute("awake")); set_awake(value); } if(cur_element.has_attribute("active")) { value = true; value = StringHelp::text_to_bool(cur_element.get_attribute("active")); set_active(value); } if(cur_element.has_attribute("bullet")) { value = false; value = StringHelp::text_to_bool(cur_element.get_attribute("bullet")); set_as_bullet(value); } if(cur_element.has_attribute("can_sleep")) { value = true; value = StringHelp::text_to_bool(cur_element.get_attribute("can_sleep")); allow_sleep(value); } } cur_node = cur_node.get_next_sibling(); } }
BIT_API Angle Degrees( const Float64 & p_Degrees ) { return Angle( p_Degrees * Pi / 180.0f ); }
AngleInt( iXY &vec ) { angle_int = Angle(vec).DegreesInt(); }
AngleInt( long x, long y) { angle_int = Angle(x,y).DegreesInt(); }
void Inertie::upBones() { _bones.angle[Bones::FOOT1] = Angle(MGRAD_CAP(MTIME * 3, -80, 50), 0); _bones.angle[Bones::FOOT2] = Angle(MGRAD_CAP(MTIME * 4, -80, 50), 0); _bones.angle[Bones::KNEE1] = Angle(MGRAD_CAP(MTIME, -35, 30), 0); _bones.angle[Bones::KNEE2] = Angle(MGRAD_CAP(MTIME, -65, 30), 0); _bones.angle[Bones::HAND1] = Angle(MGRAD_CAP(MTIME * 3, 10, 50), 0); _bones.angle[Bones::ELBOW1] = Angle(MGRAD_CAP(MTIME, 195, 30), 0); if (_player[THROW_SHURIKEN]->val()) { _bones.angle[Bones::HAND2] = Angle(MGRAD_CAP(MTIME * 4, 10, 50), 0); _bones.angle[Bones::ELBOW2] = Angle(MGRAD_CAP(MTIME, 225, 30), 0); } _bones.angle[Bones::HEAD] = Angle(-40, 0); _bones.angle[Bones::BODY] = Angle(-80, 0); _bones.angle[Bones::BODY] = Angle(60 - _player.sy() * 20 + MGRAD_CAP(MTIME / 4, -60, 20), 0); //std::cout << MGRAD_CAP(MTIME / 4, -60, 20) << std::endl; }
float RotatingLineList::CurrentAngle() { return Angle(centerx, centery, trackx, tracky); }
Angle Vec3<Type>::angle(const Vec3<Type>& v) const { return Angle(acosf(float(dot(v) / (length()*v.length()))), angle_radians); }
bool DSN6File::readHeader() throw() { // first read the complete 512 bytes of header information char header[512]; std::fstream::read(header, 512); if (gcount() != 512) { Log.error() << "DSN6File::readHeader(): File does not contain a proper DSN6 header. Aborting read." << std::endl; return false; } // to determine whether we have to swap bytes in the header (depending on the version of // the DSN6 - File and on the byte order on the machine) we try to reproduce the known value // of 100 in header[2*18] short int header_value = readHeaderValue_(header, 18); if (header_value != 100) { // try to change endianness swap_bytes_ = true; header_value = readHeaderValue_(header, 18); if (header_value != 100) { Log.error() << "DSN6File::readHeader(): Corrupt DSN6 header: header[16] != 100. Aborting read." << std::endl; return false; } } header_value = readHeaderValue_(header, 0); start_.x = (float)header_value; header_value = readHeaderValue_(header, 1); start_.y = (float)header_value; header_value = readHeaderValue_(header, 2); start_.z = (float)header_value; header_value = readHeaderValue_(header, 3); extent_.x = (float)header_value; header_value = readHeaderValue_(header, 4); extent_.y = (float)header_value; header_value = readHeaderValue_(header, 5); extent_.z = (float)header_value; header_value = readHeaderValue_(header, 6); sampling_rate_.x = (float)header_value; header_value = readHeaderValue_(header, 7); sampling_rate_.y = (float)header_value; header_value = readHeaderValue_(header, 8); sampling_rate_.z = (float)header_value; header_value = readHeaderValue_(header, 17); cell_scaling_ = (float)header_value; header_value = readHeaderValue_(header, 9); crystal_dimension_.x = (float)header_value / (cell_scaling_ * sampling_rate_.x); header_value = readHeaderValue_(header, 10); crystal_dimension_.y = (float)header_value / (cell_scaling_ * sampling_rate_.y); header_value = readHeaderValue_(header, 11); crystal_dimension_.z = (float)header_value / (cell_scaling_ * sampling_rate_.z); header_value = readHeaderValue_(header, 12); alpha_ = Angle((float)header_value / cell_scaling_, false); header_value = readHeaderValue_(header, 13); beta_ = Angle((float)header_value / cell_scaling_, false); header_value = readHeaderValue_(header, 14); gamma_ = Angle((float)header_value / cell_scaling_, false); header_value = readHeaderValue_(header, 15); prod_ = (float)header_value / 100.; header_value = readHeaderValue_(header, 16); plus_ = (float)header_value; // convert from grid space to cartesian coordinates (inspired by the VMD code :-) ) Vector3 x_tmp(crystal_dimension_.x, 0., 0.); Vector3 y_tmp(cos(gamma_.toRadian()), sin(gamma_.toRadian()), 0.); y_tmp *= crystal_dimension_.y; Vector3 z_tmp( cos(beta_.toRadian()), (cos(alpha_.toRadian()) - cos(beta_.toRadian())*cos(gamma_.toRadian())) / sin(gamma_.toRadian()), 0.); z_tmp.z = sqrt(1.0 - z_tmp.x*z_tmp.x - z_tmp.y*z_tmp.y); z_tmp *= crystal_dimension_.z; origin_.x = x_tmp.x * start_.x + y_tmp.x * start_.y + z_tmp.x * start_.z; origin_.y = y_tmp.y * start_.y + z_tmp.y * start_.z; origin_.z = z_tmp.z * start_.z; xaxis_.x = x_tmp.x * (extent_.x - 1); xaxis_.y = 0.; xaxis_.z = 0.; yaxis_.x = y_tmp.x * (extent_.y - 1); yaxis_.y = y_tmp.y * (extent_.y - 1); yaxis_.z = 0.; zaxis_.x = z_tmp.x * (extent_.z - 1); zaxis_.y = z_tmp.y * (extent_.z - 1); zaxis_.z = z_tmp.z * (extent_.z - 1); // that's it. we're done return true; }
Angle Vec3<Type>::angle_normed(const Vec3<Type>& v) const { return Angle(acosf(float(dot(v))), angle_radians); }
// ----------------------------------------------------------------------------- Angle Angle::FromDegrees(const float degrees) { return Angle(ConvertToRadians (degrees)); }
void TestApp::test_vector2(void) { Console::write_line(" Header: cl_vector.h"); Console::write_line(" Class: Vec2"); Console::write_line(" Function: rotate()"); { Vec2i test_a; Vec2i hotspot(1,3); test_a = Vec2i(4,5); test_a.rotate(hotspot, Angle(0, angle_degrees)); if (test_a != Vec2i(4, 5)) fail(); test_a = Vec2i(4,5); test_a.rotate(hotspot, Angle(90, angle_degrees)); if (test_a != Vec2i(-1, 6)) fail(); test_a = Vec2i(4,5); test_a.rotate(hotspot, Angle(180, angle_degrees)); if (test_a != Vec2i(-2, 1)) fail(); test_a = Vec2i(4,5); test_a.rotate(hotspot, Angle(270, angle_degrees)); if (test_a != Vec2i(3, 0)) fail(); test_a = Vec2i(4,5); test_a.rotate(hotspot, Angle(360, angle_degrees)); if (test_a != Vec2i(4, 5)) fail(); test_a = Vec2i(4,5); test_a.rotate(Vec2i(0,0), Angle(180, angle_degrees)); if (test_a != Vec2i(-4, -5)) fail(); } Console::write_line(" Function: distance()"); { Vec2d test_a(2.0,3.0); Vec2d test_b(3.0,4.0); if (test_a.distance(test_b) != sqrt(1.0 + 1.0 )) fail(); } Console::write_line(" Function: normalize()"); { Vec2d testi(3.0,4.0); testi.normalize(); if (testi != Vec2d(3.0/sqrt(25.0), 4.0/sqrt(25.0))) fail(); } Console::write_line(" Function: static normalize()"); { Vec2d testi(3.0,4.0); if (Vec2d::normalize(testi) != Vec2d(3.0/sqrt(25.0), 4.0/sqrt(25.0))) fail(); } Console::write_line(" Function: length()"); { Vec2d testi(3.0,4.0); if (testi.length() != sqrt(25.0 )) fail(); } Console::write_line(" Function: dot()"); { Vec2d test_a(3.0,4.0); Vec2d test_b(13.0,14.0); if (test_a.dot(test_b) != ((3.0 * 13.0)+ (4.0*14.0))) fail(); } Console::write_line(" Function: operator += (const Vec2<Type>& vector)"); { Vec2d testd(2.5, 3.5); testd += Vec2d(1.0, 2.0); if (testd.x != 3.5) fail(); if (testd.y != 5.5) fail(); Vec2i testi(2, 3); testi += Vec2i(1, 2); if (testi.x != 3) fail(); if (testi.y != 5) fail(); } Console::write_line(" Function: operator += ( Type value)"); { Vec2d testd(2.5, 3.5); double valued = 2.0; testd += valued; if (testd.x != 4.5) fail(); if (testd.y != 5.5) fail(); Vec2i testi(2, 3); int valuei = 2; testi += valuei; if (testi.x != 4) fail(); if (testi.y != 5) fail(); } Console::write_line(" Function: operator + (Type value)"); { Vec2d testd(2.5, 3.5); double valued = 2.0; testd = testd + valued; if (testd.x != 4.5) fail(); if (testd.y != 5.5) fail(); Vec2i testi(2, 3); int valuei = 2; testi = testi + valuei; if (testi.x != 4) fail(); if (testi.y != 5) fail(); } Console::write_line(" Function: operator + (const Vec2<Type>& vector)"); { Vec2d testd(2.5, 3.5); testd = testd + Vec2d(1.5, 2.5); if (testd.x != 4.0) fail(); if (testd.y != 6.0) fail(); Vec2i testi(2, 3); testi = testi + Vec2i(1, 2); if (testi.x != 3) fail(); if (testi.y != 5) fail(); } Console::write_line(" Function: operator -= (const Vec2<Type>& vector)"); { Vec2d testd(2.5, 3.5); testd -= Vec2d(1.0, 2.0); if (testd.x != 1.5) fail(); if (testd.y != 1.5) fail(); Vec2i testi(2, 3); testi -= Vec2i(1, 2); if (testi.x != 1) fail(); if (testi.y != 1) fail(); } Console::write_line(" Function: operator -= ( Type value)"); { Vec2d testd(2.5, 3.5); double valued = 2.0; testd -= valued; if (testd.x != 0.5) fail(); if (testd.y != 1.5) fail(); Vec2i testi(2, 3); int valuei = 2; testi -= valuei; if (testi.x != 0) fail(); if (testi.y != 1) fail(); } Console::write_line(" Function: operator - (Type value)"); { Vec2d testd(2.5, 3.5); double valued = 2.0; testd = testd - valued; if (testd.x != 0.5) fail(); if (testd.y != 1.5) fail(); Vec2i testi(2, 3); int valuei = 2; testi = testi - valuei; if (testi.x != 0) fail(); if (testi.y != 1) fail(); } Console::write_line(" Function: operator - (const Vec2<Type>& vector)"); { Vec2d testd(2.5, 3.5); testd = testd - Vec2d(1.5, 2.5); if (testd.x != 1.0) fail(); if (testd.y != 1.0) fail(); Vec2i testi(2, 3); testi = testi - Vec2i(1, 2); if (testi.x != 1) fail(); if (testi.y != 1) fail(); } Console::write_line(" Function: operator *= (const Vec2<Type>& vector)"); { Vec2d testd(2.5, 3.5); testd *= Vec2d(1.0, 2.0); if (testd.x != 2.5) fail(); if (testd.y != 7.0) fail(); Vec2i testi(2, 3); testi *= Vec2i(1, 2); if (testi.x != 2) fail(); if (testi.y != 6) fail(); } Console::write_line(" Function: operator *= ( Type value)"); { Vec2d testd(2.5, 3.5); double valued = 2.0; testd *= valued; if (testd.x != 5.0) fail(); if (testd.y != 7.0) fail(); Vec2i testi(2, 3); int valuei = 2; testi *= valuei; if (testi.x != 4) fail(); if (testi.y != 6) fail(); } Console::write_line(" Function: operator * (Type value)"); { Vec2d testd(2.5, 3.5); double valued = 2.0; testd = testd * valued; if (testd.x != 5.0) fail(); if (testd.y != 7.0) fail(); Vec2i testi(2, 3); int valuei = 2; testi = testi * valuei; if (testi.x != 4) fail(); if (testi.y != 6) fail(); } Console::write_line(" Function: operator * (const Vec2<Type>& vector)"); { Vec2d testd(2.5, 3.5); testd = testd * Vec2d(1.5, 2.5); if (testd.x != 3.75) fail(); if (testd.y != 8.75) fail(); Vec2i testi(2, 3); testi = testi * Vec2i(1, 2); if (testi.x != 2) fail(); if (testi.y != 6) fail(); } Console::write_line(" Function: operator /= (const Vec2<Type>& vector)"); { Vec2d testd(2.5, 3.5); testd /= Vec2d(1.0, 2.0); if (testd.x != 2.5) fail(); if (testd.y != 1.75) fail(); Vec2i testi(2, 10); testi /= Vec2i(1, 2); if (testi.x != 2) fail(); if (testi.y != 5) fail(); } Console::write_line(" Function: operator /= ( Type value)"); { Vec2d testd(2.5, 3.5); double valued = 2.0; testd /= valued; if (testd.x != 1.25) fail(); if (testd.y != 1.75) fail(); Vec2i testi(2, 10); int valuei = 2; testi /= valuei; if (testi.x != 1) fail(); if (testi.y != 5) fail(); } Console::write_line(" Function: operator / (Type value)"); { Vec2d testd(2.5, 3.5); double valued = 2.0; testd = testd / valued; if (testd.x != 1.25) fail(); if (testd.y != 1.75) fail(); Vec2i testi(2, 10); int valuei = 2; testi = testi / valuei; if (testi.x != 1) fail(); if (testi.y != 5) fail(); } Console::write_line(" Function: operator / (const Vec2<Type>& vector)"); { Vec2d testd(2.5, 3.5); testd = testd / Vec2d(1.0, 2.5); if (testd.x != 2.5) fail(); if (testd.y != 1.4) fail(); Vec2i testi(2, 10); testi = testi / Vec2i(1, 2); if (testi.x != 2) fail(); if (testi.y != 5) fail(); } Console::write_line(" Function: operator = (const Vec2<Type>& vector)"); { Vec2d testd(2.5, 3.5); testd = Vec2d(1.0, 2.0); if (testd.x != 1.0) fail(); if (testd.y != 2.0) fail(); Vec2i testi(2, 3); testi = Vec2i(1, 2); if (testi.x != 1) fail(); if (testi.y != 2) fail(); } Console::write_line(" Function: operator == (const Vec2<Type>& vector)"); { Vec2d testd(2.5, 3.5); if (testd == Vec2d(1.0, 2.0)) fail(); if (testd == Vec2d(2.5, 2.0)) fail(); if (!(testd == Vec2d(2.5, 3.5))) fail(); Vec2i testi(2, 3); if (testi == Vec2i(1, 2)) fail(); if (testi == Vec2i(2, 2)) fail(); if (!(testi == Vec2i(2, 3))) fail(); } Console::write_line(" Function: operator != (const Vec2<Type>& vector)"); { Vec2d testd(2.5, 3.5); if (!(testd != Vec2d(1.0, 2.0))) fail(); if (!(testd != Vec2d(2.5, 2.0))) fail(); if ((testd != Vec2d(2.5, 3.5))) fail(); Vec2i testi(2, 3); if (!(testi != Vec2i(1, 2))) fail(); if (!(testi != Vec2i(2, 2))) fail(); if ((testi != Vec2i(2, 3))) fail(); } Console::write_line(" Function: round()"); { Vec2d testd(2.0, 2.5); testd.round(); if (testd.x != 2.0) fail(); if (testd.y != 3.0) fail(); Vec2f testf(2.0f, 2.5f); testf.round(); if (testf.x != 2.0f) fail(); if (testf.y != 3.0f) fail(); } Console::write_line(" Function: static round()"); { Vec2d testd(2.0, 2.5); Vec2d destd = Vec2d::round(testd); if (destd.x != 2.0) fail(); if (destd.y != 3.0) fail(); Vec2f testf(2.0f, 2.5f); Vec2f destf = Vec2f::round(testf); if (destf.x != 2.0f) fail(); if (destf.y != 3.0f) fail(); } }
// ----------------------------------------------------------------------------- Angle operator * ( const float scaler, const Angle& angle) { return Angle(angle) *= scaler; }
inline const Angle operator - ( const Angle & angle ) { return Angle( -angle.radian() ); }
// ----------------------------------------------------------------------------- Angle Angle::operator + ( const Angle& angle) const { return Angle(*this) += angle; }
inline const Angle operator / ( const Angle & a1, const Angle & a2 ) { return Angle( a1.radian() / a2.radian() ); }
// ----------------------------------------------------------------------------- Angle Angle::operator / ( const float scaler ) const { return Angle(*this) /= scaler; }
inline const Angle operator * ( const Angle & angle, const double radian ) { return Angle( angle.radian() * radian ); }
Angle Angle::operator / (const double dd) { return Angle(this->toDouble() / dd); }
float RotatingLineList::OriginalAngle() { return Angle(centerx, centery, refx, refy); }
float Angle(const sf::Vector2f &v1, const sf::Vector2f &v2) { return Angle(v1.x, v1.y, v2.x, v2.y); }
void PeptideCapProcessor::optimizeCapPosition(Chain& chain, bool start) { Vector3 translation; Atom* axis = NULL; Residue* cap = NULL; std::vector<Atom*> a; std::vector<Atom*> b; Size nr = chain.countResidues(); // cap at the beginning of a peptide if (start) { // put ACE-C to the center for (AtomIterator it = chain.getResidue(1)->beginAtom(); +it; ++it) { if (it->getName() == "N") { translation = it->getPosition(); } b.push_back(&*it); } cap = chain.getResidue(0); for (AtomIterator it = cap->beginAtom(); +it; ++it) { a.push_back(&*it); if (it->getName() == "C") { axis = &*it; } } } //cap at the end of a peptide else { for (AtomIterator it = chain.getResidue(nr-2)->beginAtom(); +it; ++it) { if (it->getName() == "C") { translation = it->getPosition(); } b.push_back(&*it); } cap = chain.getResidue(nr-1); for (AtomIterator it = cap->beginAtom(); +it; ++it) { a.push_back(&*it); if (it->getName() == "N") { axis = &*it; } } } //translate the anchor to origin TranslationProcessor tlp; tlp.setTranslation(translation*-1.0); chain.apply(tlp); //try all torsions float largest_distance = 0.0; float tmp_distance = 0.0; float torsion = 0.0; float step = 2.0; TransformationProcessor tfp; Matrix4x4 m; m.setRotation( Angle(step, false), axis->getPosition()); tfp.setTransformation(m); for (Position r = step; r <= 360; r+=step) { cap->apply(tfp); tmp_distance = computeDistance(a,b); if (largest_distance < tmp_distance) { largest_distance = tmp_distance; torsion = r; } } //apply best rotation angle m.setRotation( Angle(torsion, false), axis->getPosition()); tfp.setTransformation(m); cap->apply(tfp); //now translate the protein back tlp.setTranslation(translation); chain.apply(tlp); }