Sphere Calculation, simple c program
View previous topic | View next topic >
Post new topic Reply to topic
M.A.I.L. Forum Index -> Knitting Circle
   
Author Message

Joined: January 28, 2018
Posts: 1
Submissions: 0
Location: New Braunfels, TX, USA 78130

Sphere Calculation, simple c program
Reply with quote
Posted on Mon Aug 19, 2019 1:54 pm
Link to Post: Link to Post

Below I have posted output and code for a sphere calculator using the equation I developed back in 2008. I think it works but it does require testing on a small sphere, possibly one from the articles I wrote here.

The code is still clumsy as it requires a c compiler to produce any output as I have to add command line option parsing and / or prompting and / or text file input. Maybe all of them.

If anyone would not mind hosting it on GitHub for me, that would be greatly appreciated. For some reason GitHub escapes me as I cannot grok it at all.

I could ramble on forever with details on this topic, but that's enough so here it is.

Les "Inventor" Hall



Quote:
Chainmaille Sphere Calculator
All dimensions are in millimeters.
Weave is European 8 in 1

D = 76.20 sphere diameter
ID = 12.70 ring inside diameter
WD = 2.40 wire diameter
kh = 0.47 horizontal spacing constant
kv = 0.75 vertical spacing constant

n | m
_____|______
0 | 40
1 | 39
2 | 35
3 | 29
4 | 22
5 | 13
6 | 3

total rings = 322




Code:
// Open Spheres program
// by Les Hall
// started 18 August 2019
//


#include <math>
#include <stdio>



int main() {

        // declare input variables
        double D = 3.0 * 25.4;
        double ID = 12.7;
        double WD = 2.4;
        double kh = 0.47;
        double kv = 0.75;

        // print input variables
        printf("\n\nChainmaille Sphere Calculator\n");
        printf("All dimensions are in millimeters.\n");
        printf("Weave is European 8 in 1\n");
        printf("\nD = %0.2f sphere diameter\n", D);
        printf("ID = %0.2f ring inside diameter\n", ID);
        printf("WD = %0.2f wire diameter\n", WD);
        printf("kh = %0.2f horizontal spacing constant\n", kh);
        printf("kv = %0.2f vertical spacing constant\n", kv);

        // declare calculation variables
        int n = 0;
        int m = 0;
        int total = 0;
        double R = D/2.0;

        printf("\n      n  |   m\n    _____|______\n");
        // print rings per frow (m)
        do {
                // calculate rings per row (m)
                m = (int) round(2 * 3.141592 * R / (kh*ID) *
                        cos(kv * ID / R * n) );
                if (m > 0) {
                        // keep track of the total number of rings
                        total += (n == 0 ? m : 2*m);
                        // print rings per frow (m)
                        printf("    %3i  |  %2i\n", n, m);
                        n++;
                }
        } while(m > 0);
        printf("\ntotal rings = %i\n", total);
        printf("\n\n");

        return 0;
}



Les Hall

Let's make the world a better place.
I'm the person who dreamed up spherical spheres.

Post new topic Reply to topic
Jump to:  
Page 1 of 1
All times are GMT. The time now is Fri Dec 13, 2019 11:30 pm
M.A.I.L. Forum Index -> Knitting Circle
Display posts from previous: