70 #include "input_output/FGXMLElement.h" 71 #include "input_output/FGPropertyManager.h" 77 IDENT(IdSrc,
"$Id: FGAngles.cpp,v 1.5 2016/07/27 22:42:47 andgi Exp $");
78 IDENT(IdHdr,ID_ANGLES);
86 FGAngles::FGAngles(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
90 source_angle_unit = 1.0;
91 target_angle_unit = 1.0;
94 if (element->FindElement(
"target_angle") ) {
95 target_angle_pNode = PropertyManager->GetNode(element->FindElementValue(
"target_angle"));
96 if (element->FindElement(
"target_angle")->HasAttribute(
"unit")) {
97 if (element->FindElement(
"target_angle")->GetAttributeValue(
"unit") ==
"DEG") {
98 target_angle_unit = 0.017453293;
102 throw(
"Target angle is required for component: "+Name);
105 if (element->FindElement(
"source_angle") ) {
106 source_angle_pNode = PropertyManager->GetNode(element->FindElementValue(
"source_angle"));
107 if (element->FindElement(
"source_angle")->HasAttribute(
"unit")) {
108 if (element->FindElement(
"source_angle")->GetAttributeValue(
"unit") ==
"DEG") {
109 source_angle_unit = 0.017453293;
113 throw(
"Source latitude is required for Angles component: "+Name);
116 unit = element->GetAttributeValue(
"unit");
118 if (unit ==
"DEG") output_unit = 180.0/M_PI;
119 else if (unit ==
"RAD") output_unit = 1.0;
120 else throw(
"Unknown unit "+unit+
" in angle component, "+Name);
125 FGFCSComponent::bind();
131 FGAngles::~FGAngles()
138 bool FGAngles::Run(
void )
140 source_angle = source_angle_pNode->getDoubleValue() * source_angle_unit;
141 target_angle = target_angle_pNode->getDoubleValue() * target_angle_unit;
143 double x1 = cos(source_angle);
144 double y1 = sin(source_angle);
145 double x2 = cos(target_angle);
146 double y2 = sin(target_angle);
148 double x1x2_y1y2 = max(-1.0, min(x1*x2 + y1*y2, 1.0));
149 double angle_to_heading_rad = acos(x1x2_y1y2);
153 if (x1y2 >= x2y1) Output = angle_to_heading_rad * output_unit;
154 else Output = -angle_to_heading_rad * output_unit;
157 if (IsOutput) SetOutput();
181 void FGAngles::Debug(
int from)
183 if (debug_lvl <= 0)
return;
189 if (debug_lvl & 2 ) {
190 if (from == 0) cout <<
"Instantiated: FGAngles" << endl;
191 if (from == 1) cout <<
"Destroyed: FGAngles" << endl;
193 if (debug_lvl & 4 ) {
195 if (debug_lvl & 8 ) {
197 if (debug_lvl & 16) {
199 if (debug_lvl & 64) {
201 cout << IdSrc << endl;
202 cout << IdHdr << endl;