Пример #1
0
double AVGeoPoint::distanceInKillometersTo(AVGeoPoint* point) {
  double theta = this->longitude - point->longitude;
  double dist = sin(degreeToRadian(this->latitude)) * sin(degreeToRadian(point->latitude))
                + cos(degreeToRadian(this->latitude)) * cos(degreeToRadian(point->latitude))
                * cos(degreeToRadian(theta));

  dist = acos(dist);
  dist = radianToDegree(dist);
  dist = dist * 60 * 1.1515 * 1.609344;

  return dist;
}
Пример #2
0
 static inline float acos (float v)
 {
     if ( -1.0 < v )
     {
         if ( v < 1.0 )
             return radianToDegree(::acos(v));
         else
             return 0.0;
     }
     else
     {
         return 180.0;
     }
 }
Пример #3
0
 static inline float asin (float v)
 {
     if ( -1.0 < v )
     {
         if ( v < 1.0 )
             return radianToDegree(::asin(v));
         else
             return 90.0;
     }
     else
     {
         return -90.0;
     }
 }
Пример #4
0
void Camera::rotate(const long double &angleX, const long double &angleY, const long double &/*angleZ*/)
{
    // TODO: Добавить поворот камеры по Z (UP-vector).
    Vec3f oldPosition = m_position - m_lookAt;
    
    long double r = oldPosition.length();
    
    if (radianToDegree(m_theta) >= 5.0L && radianToDegree(m_theta) <= 175.0L) {
        m_theta += angleX;
    } else {
        if (radianToDegree(m_theta) < 5.0L) {
            m_theta = degreeToRadian(5.0L);
        } else {
            m_theta = degreeToRadian(175.0L);
        }
    }
    
    m_phi += angleY;
    
    Vec3f newPosition = Vec3f(r * std::sin(m_theta) * std::sin(m_phi), r * std::cos(m_theta), -r * std::sin(m_theta) * std::cos(m_phi));
    
    m_position = newPosition + m_lookAt;
}
float normalizeAngle(float degree) {
    return radianToDegree(atan2(sin(degreeToRadian(degree)), cos(degreeToRadian(degree))));
}
Пример #6
0
 static inline float atan (float v)
 {
     return radianToDegree(::atan(v));
 }
Пример #7
0
void Angle::setRadians(float radians) {
	_degrees = radianToDegree(radians);
}
Пример #8
0
Angle Angle::fromRadians(float radians) {
	return Angle(radianToDegree(radians));
}
Пример #9
0
bool SXMath::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) {
	//////////////////////////////////////////////////////////////////////////
	// Abs
	//////////////////////////////////////////////////////////////////////////
	if (strcmp(name, "Abs") == 0) {
		stack->correctParams(1);
		stack->pushFloat(fabs(stack->pop()->getFloat()));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Acos
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Acos") == 0) {
		stack->correctParams(1);
		stack->pushFloat(acos(stack->pop()->getFloat()));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Asin
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Asin") == 0) {
		stack->correctParams(1);
		stack->pushFloat(asin(stack->pop()->getFloat()));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Atan
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Atan") == 0) {
		stack->correctParams(1);
		stack->pushFloat(atan(stack->pop()->getFloat()));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Atan2
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Atan2") == 0) {
		stack->correctParams(2);
		double y = stack->pop()->getFloat();
		double x = stack->pop()->getFloat();
		stack->pushFloat(atan2(y, x));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Ceil
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Ceil") == 0) {
		stack->correctParams(1);
		stack->pushFloat(ceil(stack->pop()->getFloat()));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Cos
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Cos") == 0) {
		stack->correctParams(1);
		stack->pushFloat(cos(degreeToRadian(stack->pop()->getFloat())));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Cosh
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Cosh") == 0) {
		stack->correctParams(1);
		stack->pushFloat(cosh(degreeToRadian(stack->pop()->getFloat())));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Exp
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Exp") == 0) {
		stack->correctParams(1);
		stack->pushFloat(exp(stack->pop()->getFloat()));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Floor
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Floor") == 0) {
		stack->correctParams(1);
		stack->pushFloat(floor(stack->pop()->getFloat()));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Log
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Log") == 0) {
		stack->correctParams(1);
		stack->pushFloat(log(stack->pop()->getFloat()));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Log10
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Log10") == 0) {
		stack->correctParams(1);
		stack->pushFloat(log10(stack->pop()->getFloat()));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Pow
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Pow") == 0) {
		stack->correctParams(2);
		double x = stack->pop()->getFloat();
		double y = stack->pop()->getFloat();

		stack->pushFloat(pow(x, y));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Sin
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Sin") == 0) {
		stack->correctParams(1);
		stack->pushFloat(sin(degreeToRadian(stack->pop()->getFloat())));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Sinh
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Sinh") == 0) {
		stack->correctParams(1);
		stack->pushFloat(sinh(degreeToRadian(stack->pop()->getFloat())));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Tan
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Tan") == 0) {
		stack->correctParams(1);
		stack->pushFloat(tan(degreeToRadian(stack->pop()->getFloat())));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Tanh
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Tanh") == 0) {
		stack->correctParams(1);
		stack->pushFloat(tanh(degreeToRadian(stack->pop()->getFloat())));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Sqrt
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Sqrt") == 0) {
		stack->correctParams(1);
		stack->pushFloat(sqrt(stack->pop()->getFloat()));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// DegToRad
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "DegToRad") == 0) {
		stack->correctParams(1);
		stack->pushFloat(degreeToRadian(stack->pop()->getFloat()));
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// RadToDeg
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "RadToDeg") == 0) {
		stack->correctParams(1);
		stack->pushFloat(radianToDegree(stack->pop()->getFloat()));
		return STATUS_OK;
	} else {
		return STATUS_FAILED;
	}
}