71 #include "input_output/FGXMLElement.h"
83 FGAngles::FGAngles(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
87 source_angle_unit = 1.0;
88 target_angle_unit = 1.0;
91 if (element->FindElement(
"target_angle") ) {
92 target_angle_pNode = PropertyManager->GetNode(element->FindElementValue(
"target_angle"));
93 if (element->FindElement(
"target_angle")->HasAttribute(
"unit")) {
94 if (element->FindElement(
"target_angle")->GetAttributeValue(
"unit") ==
"DEG") {
95 target_angle_unit = 0.017453293;
99 throw(
"Target angle is required for component: "+Name);
102 if (element->FindElement(
"source_angle") ) {
103 source_angle_pNode = PropertyManager->GetNode(element->FindElementValue(
"source_angle"));
104 if (element->FindElement(
"source_angle")->HasAttribute(
"unit")) {
105 if (element->FindElement(
"source_angle")->GetAttributeValue(
"unit") ==
"DEG") {
106 source_angle_unit = 0.017453293;
110 throw(
"Source latitude is required for Angles component: "+Name);
113 unit = element->GetAttributeValue(
"unit");
115 if (unit ==
"DEG") output_unit = 180.0/M_PI;
116 else if (unit ==
"RAD") output_unit = 1.0;
117 else throw(
"Unknown unit "+unit+
" in angle component, "+Name);
128 FGAngles::~FGAngles()
135 bool FGAngles::Run(
void )
137 source_angle = source_angle_pNode->getDoubleValue() * source_angle_unit;
138 target_angle = target_angle_pNode->getDoubleValue() * target_angle_unit;
140 double x1 = cos(source_angle);
141 double y1 = sin(source_angle);
142 double x2 = cos(target_angle);
143 double y2 = sin(target_angle);
145 double x1x2_y1y2 = max(-1.0, min(x1*x2 + y1*y2, 1.0));
146 double angle_to_heading_rad = acos(x1x2_y1y2);
150 if (x1y2 >= x2y1) Output = angle_to_heading_rad * output_unit;
151 else Output = -angle_to_heading_rad * output_unit;
178 void FGAngles::Debug(
int from)
180 if (debug_lvl <= 0)
return;
186 if (debug_lvl & 2 ) {
187 if (from == 0) cout <<
"Instantiated: FGAngles" << endl;
188 if (from == 1) cout <<
"Destroyed: FGAngles" << endl;
190 if (debug_lvl & 4 ) {
192 if (debug_lvl & 8 ) {
194 if (debug_lvl & 16) {
196 if (debug_lvl & 64) {