This is a file from the Wikimedia Commons

File:Rotation with rational angle 3 over 7.svg

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Original file(SVG file, nominally 709 × 709 pixels, file size: 2 KB)

Summary

Description
English: rotation with rational angle 3 over 7
Date
Source Own work
Author Adam majewski
Other versions
 
W3C-validity not checked.

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

C src code

/*

c console program based on :
cpp code by Claudio Rocchini

[[:File:Poincare_halfplane_eptagonal_hb.svg]]

http://validator.w3.org/
The uploaded document “circle.svg” was successfully checked as SVG 1.1.
This means that the resource in question identified itself as “SVG 1.1”
and that we successfully performed a formal validation using an SGML, HTML5 and/or XML
Parser(s) (depending on the markup language used).

------- git -----------------
cd existing_folder
git init
git remote add origin git@gitlab.com:adammajewski/svg_rotation.git
git add s.c
git commit -m " first commit"
git push -u origin master

-------- how to use --------
gcc s.c -Wall -lm
./a.out

*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

// rotation angle = combinatorial rotation number = internal angle 
 int numerator = 3;
 int denominator = 7; 

const double PI = 3.1415926535897932384626433832795;

 int  iXmax = 1000,
           iYmax = 1000,
           radius,
           cx,
           cy;

 // http://www.december.com/html/spec/color4.html  
char *black    = "#000000"; /* hexadecimal number as a string for svg color*/
char *white    = "#FFFFFF";
char *burgundy = "#9E0508";
 char *SeaGreen = "#068481";
char *turquoise= "#40E0D0";
char *red      = "#FF0000";
char *navy     = "#000080";
char *blue     = "#0000FF";

	 	 

 FILE * fp;
 char *filename="circle.svg";
 char *comment = "<!-- sample comment in SVG file  \n can be multi-line -->";

// ----------------- functions -------------------------------

#define MIN(a,b) (((a)<(b))?(a):(b))

void beginSVG(){

 fp = fopen( filename,"w");
 if( fp == NULL ) {printf (" file open error \n"); return ; }

 fprintf(fp,
     "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
     "%s \n "
           "<svg width=\"20cm\" height=\"20cm\" viewBox=\"0 0 %d %d \"\n"
           " xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
           comment,iXmax,iYmax);

  

printf(" begin done \n");

}

void EndSVG(){
fprintf(fp,"</svg>\n");
 fclose(fp);
 printf(" file %s saved \n",filename );
}

void draw_main_circle( char *stroke_c, char *fill_c)
{

    // center 
    cx= iXmax/2;
    cy = iYmax/2;
    // adjust radius
    radius = MIN(cx, cy)- 2*MIN(cx, cy)/10;
    //
    fprintf(fp,"<circle cx=\"%d\" cy=\"%d\" r=\"%d\" style=\"stroke:%s; stroke-width:2; fill:%s\"/>\n",
    cx, cy, radius, stroke_c, fill_c);

  // printf(" draw main circle done \n");

}

/*
<!-- Mark relevant points -->
  <g stroke="black" stroke-width="3" fill="black">
    <circle id="pointA" cx="100" cy="350" r="3" />
    <circle id="pointB" cx="250" cy="50" r="3" />
    <circle id="pointC" cx="400" cy="350" r="3" />
  </g>
  <!-- Label the points -->
  <g font-size="30" font-family="sans-serif" fill="black" stroke="none" text-anchor="middle">
    <text x="100" y="350" dx="-30">A</text>
    <text x="250" y="50" dy="-10">B</text>
    <text x="400" y="350" dx="30">C</text>
  </g>

mark point by drawing a smalll circle 

*/
void mark_point(  int num, int den, char *stroke_c, char *fill_c)
{

   int _cx, _cy;
   int r = radius/30;  // adjust radius
   // compute center
   double angle = 2.0*PI*(double)num/den;
   // label
   int length = 1+snprintf( NULL, 0, "%d %s %d", num, " / ", den ); // http://stackoverflow.com/questions/8257714/how-to-convert-an-int-to-string-in-c
   char* label = malloc( length + 1 );

   
    // center of local circle 
    _cx = cx + (int) round(radius*cos(angle));
    _cy = iYmax - (cy + (int)round(radius*sin(angle))); // reverse Y axis
   
    // mark point
    fprintf(fp,"<circle cx=\"%d\" cy=\"%d\" r=\"%d\" style=\"stroke:%s; stroke-width:2; fill:%s\"/>\n",
    _cx, _cy, r , stroke_c, fill_c);

    // label 
    snprintf(label, length, "%d %s %d", num,"/",  den); // snprintf( str, length + 1, "%d", x );
    fprintf(fp,"<text x=\"%d\" y=\"%d\" style=\"font-family: Arial; font-size  : 20; stroke : %s; fill : %s;\">%s</text>\n", 
         cx + (int) round((radius+4*r)*cos(angle)), iYmax - (cy + (int)round((radius+4*r)*sin(angle))), fill_c, fill_c, label );

   free(label);
  // printf(" mark point done \n");

}

void draw_line(int n1, int n2, int d, char *stroke_c){

 double angle1 = 2.0*PI*(double)n1/d;
 double angle2 = 2.0*PI*(double)n2/d;
 int x1 = cx + (int) round(radius*cos(angle1));
 int y1 = iYmax - (cy + (int)round(radius*sin(angle1))); // reverse Y axis
 int x2 = cx + (int) round(radius*cos(angle2));
 int y2 = iYmax - (cy + (int)round(radius*sin(angle2))); // reverse Y axis

 fprintf(fp,"<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\" stroke: %s; stroke-width:5\" />\n",x1, y1, x2, y2, stroke_c );

}

// ------------------------------------- main ---------------------------------------------------
int main(){
    
 int i; 
 int in;
 

 int n = numerator;
 int new_n;

 // Intinerary
 char *color;
// char *0_color = red;
// char *1_color = green;
 int n0max = denominator- numerator; 
  printf(" n0max  = %d \n", n0max);
   
 beginSVG();    

 
 
 draw_main_circle( black, white);
 // mark points 
 for (i = 0; i < denominator ; i++)
         { 

         mark_point( n,denominator, black, color);
         new_n = (n+numerator) % denominator; // circle map 
         if (n<=n0max && n>0) {color = "#FF0000"; in = 0;}else {color = "#068481"; in = 1;}
         printf(" %d %s %d  = %d \n", n , "/", denominator, in);
        
         
         draw_line(n, new_n, denominator, black );
         n = new_n;

          }
      
 EndSVG();

 
 
 return 0;
}
}

Text output :


n0max  = 4 
 begin done 
 3 / 7  = 0 
 6 / 7  = 1 
 2 / 7  = 0 
 5 / 7  = 1 
 1 / 7  = 0 
 4 / 7  = 0 
 0 / 7  = 1 
 file 3o7.svg saved 
itinerary = 0101001
 first external angle  = 41 / 127 

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

10 January 2016

image/svg+xml

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current20:24, 10 January 2016Thumbnail for version as of 20:24, 10 January 2016709 × 709 (2 KB)Soul windsurfercolor = intinerary
19:12, 10 January 2016Thumbnail for version as of 19:12, 10 January 2016709 × 709 (2 KB)Soul windsurferUser created page with UploadWizard

Metadata