Guest User

Untitled

a guest
May 20th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. struct punkt{
  6.     float x;
  7.     float y;
  8.     float z;
  9. };
  10.  
  11. int licz_punkty(int il_war, int il_scianek, float r){
  12.     int war;
  13.     int sciana;
  14.     float kat = 3.1416 /il_scianek*2;
  15.     float z;
  16.     float mod_warstw;
  17.     int sx;
  18.     float ostatni_l;
  19.     float ostatni_p;
  20.  
  21.     struct punkt **tablica;
  22.     tablica = (struct punkt**) malloc(il_war * sizeof(struct punkt*));
  23.     for(sx = 0; sx < il_war; ++sx){
  24.         tablica[sx] = (struct punkt*)malloc(il_scianek * sizeof(struct punkt));
  25.     }
  26.  
  27.  
  28.     for(war=1;war<il_war;war++){
  29.         z=r*sin(war*kat);
  30.         mod_warstw=r*cos(war*kat);
  31.         for(sciana=0;sciana<il_scianek;sciana++){
  32.             tablica[war][sciana].x=cos(sciana*kat)*mod_warstw;
  33.             tablica[war][sciana].y=sin(sciana*kat)*mod_warstw;
  34.             tablica[war][sciana].z = z;
  35.         }
  36.     }
  37.  
  38.     for(war=1;war<il_war;war++){
  39.         for(sciana=0;sciana<il_scianek;sciana++){
  40.             ostatni_l = tablica[ (war + 1) % il_scianek ][ sciana ];
  41.             ostatni_p = tablica[ (war + 1) % il_scianek ][ (sciana + 1) % il_scianek ];
  42.         }
  43.     }
  44.  
  45.  
  46.     for(war=1;war<il_war;war++){
  47.         for(sciana=0;sciana<il_scianek;sciana++){
  48.             printf("%f %f %f \n", tablica[war][sciana].x, tablica[war][sciana].y, tablica[war][sciana].z);
  49.         }
  50.     }
  51.     return 0;
  52. };
  53.  
  54. struct punkt tworz_wektor(struct punkt a, struct punkt b){
  55.     struct punkt *wektor=(struct punkt*)malloc(sizeof(struct punkt*));
  56.     wektor->x =b.x - a.x;
  57.     wektor->x =b.y - a.y;
  58.     wektor->x =b.z - a.z;
  59.     return *wektor;
  60. };
  61.  
  62. struct punkt tworz_normalna(struct punkt a, struct punkt b, struct punkt c){
  63.     struct punkt *normalna=(struct punkt*)malloc(sizeof(struct punkt*));
  64.     normalna->x = (a.x + b.x + c.x) / 3;
  65.     normalna->y = (a.y + b.y + c.y) / 3;
  66.     normalna->z = (a.z + b.z + c.z) / 3;
  67.  
  68.     struct punkt *zero=(struct punkt*)malloc(sizeof(struct punkt*));
  69.     zero->x = 0;
  70.     zero->y = 0;
  71.     zero->z = 0;
  72.  
  73.     return tworz_wektor(*zero,*normalna);
  74. };
  75.  
  76. int main(){
  77.     char wybor;
  78.     do{
  79.         printf("\n ---------------\n");
  80.         printf("Wybierz opcje:\n");
  81.         printf(" l - licz punkty \n");
  82.         printf(" \n");
  83.         printf(" w - wyjdz \n");
  84.         printf(" => ");
  85.         scanf("%c",&wybor);
  86.         switch(wybor){
  87.         case 'l':licz_punkty(10,10,10);
  88.         }
  89.         printf("ok\n");
  90.     }
  91.     while (wybor!='w');
  92.  
  93.     system("pause");
  94.     return 0;
  95. }
Add Comment
Please, Sign In to add comment