void accelerometer_calculate_rotation(accelerometer_info* accelerometer_angles, float x, float y, float z) {
	if (y != 0 && z != 0) {
		accelerometer_angles->pitch = radian_to_degree(atan(x / sqrt(y*y + z*z)));
	}

	if (x != 0 && z != 0) {
		accelerometer_angles->roll = radian_to_degree(atan(y / sqrt(x*x + z*z)));
	}

	if (x != 0 && y != 0) {
		accelerometer_angles->yaw = radian_to_degree(atan(z / sqrt(x*x + y*y)));
	}
}
int main ()
{
    // 異なる型(タグ)間での暗黙変換はできない
    {
        degree<float> deg(90.0f);
//      radian<float> rad = deg; // コンパイルエラー!型が違う
    }

    // degreeからradianへの変換
    {
        degree<float> deg(90.0f);
        radian<float> rad = degree_to_radian(deg);
        std::cout << rad.get() << std::endl;
    }

    // radianからdegreeへの変換
    {
        radian<float> rad(0.5 * boost::math::constants::pi<float>());
        degree<float> deg = radian_to_degree(rad);
        std::cout << deg.get() << std::endl;
    }
}
Beispiel #3
0
double calc_RPN(void)
{
	int ret;
	double i, j;
	double data;
	double stack2[100];
	int index = 0;

	f_error = 0;
	for(;;) {
		ret = get_formula(&data);
		if(ret == 1) {
			stack2[index++] = data;
		} else if(ret == 0) {
			switch((int)data) {
			case '+':
				j = stack2[--index];
				i = stack2[--index];
				stack2[index++] = i + j;
				break;
			case '-':
				j = stack2[--index];
				i = stack2[--index];
				stack2[index++] = i - j;
				break;
			case '*':
				j = stack2[--index];
				i = stack2[--index];
				stack2[index++] = i * j;
				break;
			case '/':
				j = stack2[--index];
				i = stack2[--index];
				if(j == 0) {
					fprintf(stderr, "Error: Division error\nDivision by zero\n");
					f_error = 1;
					return -1;
				}
				stack2[index++] = i / j;
				break;
			case '^':
				j = stack2[--index];
				i = stack2[--index];
				stack2[index++] = pow(i, j);
				break;
			case SIN:
				i = stack2[--index];
				if(f_use_degree)  i = radian_to_degree(i);
				stack2[index++] = sin(i);
				break;
			case COS:
				i = stack2[--index];
				if(f_use_degree)  i = radian_to_degree(i);
				stack2[index++] = cos(i);
				break;
			case TAN:
				i = stack2[--index];
				if(f_use_degree)  i = radian_to_degree(i);
				if(i == (M_PI / 2)) {
					fprintf(stderr, "Error: tan90(deg) not calculate!!\n");
					f_was_calc = 0;
					break;
				}
				stack2[index++] = tan(i);
				break;
			case ASIN:
				i = stack2[--index];
				if(f_use_degree)  i = radian_to_degree(i);
				stack2[index++] = asin(i);
				break;
			case ACOS:
				i = stack2[--index];
				if(f_use_degree)  i = radian_to_degree(i);
				stack2[index++] = acos(i);
				break;
			case ATAN:
				i = stack2[--index];
				if(f_use_degree)  i = radian_to_degree(i);
				stack2[index++] = atan(i);
				break;
			case SINH:
				i = stack2[--index];
				if(f_use_degree)  i = radian_to_degree(i);
				stack2[index++] = sinh(i);
				break;
			case COSH:
				i = stack2[--index];
				if(f_use_degree)  i = radian_to_degree(i);
				stack2[index++] = cosh(i);
				break;
			case TANH:
				i = stack2[--index];
				if(f_use_degree)  i = radian_to_degree(i);
				stack2[index++] = tanh(i);
				break;
			case SQRT:
				i = stack2[--index];
				if(i < 0) {
					fprintf(stderr, "Error: minus number is not calculate square root\n");
					f_was_calc = 0;
					break;
				}
				stack2[index++] = sqrt(i);
				break;
			case EXP:
				i = stack2[--index];
				stack2[index++] = exp(i);
				break;
			case LOG:
				i = stack2[--index];
				if(i < 0) {
					fprintf(stderr, "Error: minus number is not calculate common logarithm\n");
					f_was_calc = 0;
					break;
				}
				stack2[index++] = log10(i);
				break;
			case LN:
				i = stack2[--index];
				if(i < 0) {
					fprintf(stderr, "Error: minus number is not calculate natural logarithm\n");
					f_was_calc = 0;
					break;
				}
				stack2[index++] = log(i);
				break;
			case ABS:
				i = stack2[--index];
				stack2[index++] = abs(i);
				break;
			case NO_FUNC:
				break;
			}
		} else if(ret == -1) {
			break;
		}
	}
	i = stack2[--index];
	return i;
}