summaryrefslogtreecommitdiff
path: root/js/Misc/BOUNCE.js
blob: 5e99ad2f85b6d6aca2f87f2144e238478e39f299 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* autogenerated from "macros/Misc/BOUNCE.sci" */
function BOUNCE() {
    BOUNCE.prototype.define = function BOUNCE() {
        var n = 2;
        var k = 1;
        var ipar = [];
        for (i=1;i<=n;i+=1) {
            for (j=i+1;j<=n;j+=1) {
                ipar[k-1] = i;
                var k = k+1;
                ipar[k-1] = j;
                var k = k+1;
            }
        }
        this.walls = [[0],[5],[0],[5]];
        this.x = [[2],[2.5]];
        this.xd = [[0],[0]];
        this.y = [[3],[5]];
        this.yd = [[0],[0]];
        this.g = 9.81;
        this.C = 0;
        this.rpar1 = ones(n,1);
        this.rpar2 = this.rpar1;
        var state = [this.x,this.xd,this.y,this.yd];
        var state = transpose(state);
        this.model = scicos_model();
        this.model.sim = list(new ScilabString(["bounce_ball"]), new ScilabDouble([4]));
        this.model.in = new ScilabDouble([]);
        this.model.out = new ScilabDouble([n],[n]);
        this.model.state = new ScilabDouble(state.slice());
        this.model.rpar = new ScilabDouble([this.rpar1],[this.rpar2],[this.walls],[this.g],[this.C]);
        this.model.ipar = new ScilabDouble(ipar);
        this.model.nzcross = new ScilabDouble([n*(n-1)/2+4*n]);
        this.model.blocktype = new ScilabString(["c"]);
        this.model.dep_ut = new ScilabBoolean([false,true]);
        var exprs = [[strcat(sci2exp(this.rpar1))],[strcat(sci2exp(this.rpar2))],[strcat(sci2exp(this.walls))],[strcat(sci2exp(this.x))],[strcat(sci2exp(this.xd))],[strcat(sci2exp(this.y))],[strcat(sci2exp(this.yd))]];
        var gr_i = new ScilabString(["xstringb(orig(1),orig(2),\"BOUNCE\",sz(1),sz(2));"]);
        this.x = new standard_define(new ScilabDouble([3,2]),this.model,new ScilabDouble(exprs),gr_i);
        return new BasicBlock(this.x);
    }
    BOUNCE.prototype.details = function BOUNCE() {
        return this.x;
    }
    BOUNCE.prototype.get = function BOUNCE() {
        var options = {
            rpar1:["Mass",this.rpar1],
            rpar2:["Radius",this.rpar2],
            walls:["[xmin,xmax,ymin,ymax]",this.walls.toString().replace(/,/g," ")],
            xt:["xpos",this.xt],
            xd:["xdpos",this.xd.toString().replace(/,/g," ")],
            y:["ypos",this.y],
            yd:["ydpos",this.yd.toString().replace(/,/g," ")],
            g:["g (gravity)",this.g],
            C:["C (aerodynamic coeff",this.C],
        }
        return options;
    }
    BOUNCE.prototype.set = function BOUNCE() {
        var exprs = this.graphics.exprs;
        if (size(exprs,"*")<9) {
            exprs[8-1] = "9.81";
            exprs[9-1] = "0";
        }
        while (true) {
            var ok = true;
            this.rpar1 = parseFloat(arguments[0]["rpar1"]);
            this.rpar2 = parseFloat(arguments[0]["rpar2"]);
            this.walls = inverse(arguments[0]["walls"]);
            this.xt = inverse(arguments[0]["xt"]);
            this.xd = inverse(arguments[0]["xd"]);
            this.y = inverse(arguments[0]["y"]);
            this.yd = inverse(arguments[0]["yd"]);
            this.g = parseFloat(arguments[0]["g"]);
            this.C = parseFloat(arguments[0]["C"]);
            if (!ok) {
                break;
            }
            this.xt = this.xt.slice();
            this.y = this.y.slice();
            this.xd = this.xd.slice();
            this.yd = this.yd.slice();
            this.rpar1 = this.rpar1.slice();
            this.rpar2 = this.rpar2.slice();
            var n = size(this.xt,"*");
            this.walls = this.walls.slice();
            if (this.walls[1-1]>this.walls[2-1]) {
                this.walls = this.walls[[2,1]-1];
            }
            if (this.walls[3-1]>this.walls[3-1]) {
                this.walls = this.walls[[3,4]-1];
            }
            if (n!=size(this.y,"*")||n!=size(this.rpar1,"*")||n!=size(this.rpar2,"*")||n!=size(this.xd,"*")||n!=size(this.yd,"*")) {
                message("All vectors must have equal size");
                throw "user error";
                var ok = false;
            } else if (!(min([[this.rpar1],[this.rpar2]])>0)) {
                message("Mass and radius must be >0");
                throw "user error";
                var ok = false;
            }
            if (!ok) {
                break;
            }
            var tmpvar0 = check_io(this.model,this.graphics,[],[n,n],[],[]);
            this.model = tmpvar0[0];
            this.graphics = tmpvar0[1];
            var ok = tmpvar0[2];
            if (ok) {
                var k = 1;
                var ipar = [];
                for (i=1;i<=n;i+=1) {
                    for (j=i+1;j<=n;j+=1) {
                        ipar[k-1] = i;
                        var k = k+1;
                        ipar[k-1] = j;
                        var k = k+1;
                    }
                }
                this.model.rpar = new ScilabDouble([this.rpar1],[this.rpar2],[this.walls],[this.g],[this.C]);
                this.model.ipar = new ScilabDouble(ipar);
                var state = [this.xt,this.xd,this.y,this.yd];
                var state = transpose(state);
                this.model.state = new ScilabDouble(state.slice());
                this.model.nzcross = new ScilabDouble([n*(n-1)/2+4*n]);
                this.graphics.exprs = new ScilabDouble([exprs]);
                this.x.graphics = this.graphics;
                this.x.model = this.model;
                break;
            }
        }
        return new BasicBlock(this.x);
    }
    BOUNCE.prototype.get_popup_title = function BOUNCE() {
        var set_param_popup_title = "Set Bounce Block";
        return set_param_popup_title;
    }
}