Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<math.h>
- #define PI 3.1415926535
- typedef struct {
- double rad1, rad2;
- } radian_t;
- radian_t *radian(int, int);
- double *keisan_X(double);
- double *keisan_Y(double);
- int main(void) {
- int theta1, theta2, i;
- double X, Y, *x, *y;
- printf("Θ1の値(deg)を入力してください: ");
- scanf("%d", &theta1);
- printf("Θ2の値(deg)を入力してください: ");
- scanf("%d", &theta2);
- radian_t *rad = radian(theta1, theta2);
- X = (cos(rad->rad1) + cos(rad->rad2)) / 2.;
- Y = (sin(rad->rad1) + sin(rad->rad2)) / 2.;
- printf("x = %f, y = %f\n", X, Y);
- x = keisan_X(X);
- y = keisan_Y(Y);
- for (i = 0; i < 4; i++) {
- printf("x[%d] = %f, y[%d] = %f\n", i, x[0], i, y[0]);
- }
- return EXIT_SUCCESS;
- }
- radian_t *radian(int theta1, int theta2) {
- radian_t *rad = (radian_t *) malloc(sizeof(radian_t));
- rad->rad1 = PI * theta1 / 180.;
- rad->rad2 = PI * (theta1 + theta2) / 180.;
- return rad;
- }
- double *keisan_X(double X) {
- int a, i;
- double XX = (0 - X) / 4.;
- double *x = (double *) malloc(4 * sizeof(double));
- for (i = 0, a = 1; i < 4; i++, a++)
- x[i] = X * a * XX;
- return x;
- }
- double *keisan_Y(double Y) {
- int a, i;
- double YY = (0.8 - Y) / 4.;
- double *y = (double *) malloc(4 * sizeof(double));
- for (i = 0, a = 1; i < 4; i++, a++)
- y[0] = Y + a * YY;
- return y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement