Skip to content

Commit

Permalink
Added fixed point drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
tbh12001 committed Nov 27, 2017
1 parent dab0a13 commit 4011ffe
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions js/mobius.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ function update_vector_field(a,b,c,d){
ctx.stroke();
}
}
fp = fixedpts(a,b,c,d);
ctx.beginPath();
ctx.arc(remap(fp[0].re,-2,2,0,600),remap(fp[0].im,-2,2,600,0),5,0,Math.PI*2);
ctx.stroke();

ctx.beginPath();
ctx.arc(remap(fp[1].re,-2,2,0,600),remap(fp[1].im,-2,2,600,0),5,0,Math.PI*2)
ctx.stroke();
}

function render(a,b,c,d){
Expand All @@ -118,10 +126,6 @@ function renderGL(texture) {
gl.enableVertexAttribArray(positionLocation);
gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 0, 0);





gl.uniform2f(gl.getUniformLocation(program, "a"),a.re,a.im);
gl.uniform2f(gl.getUniformLocation(program, "b"),b.re,b.im);
gl.uniform2f(gl.getUniformLocation(program, "c"),c.re,c.im);
Expand Down Expand Up @@ -208,6 +212,25 @@ var mobius_inv = function(a,b,c,d,z){
return c.multiply(Complex(-1,0)).multiply(z).add(a).reciprocal().multiply(b.multiply(Complex(-1,0)).add(z.multiply(d)));
}

function cpxSqrt(z) {
x = z.re;
y = z.im;
factor = Math.pow(x*x+y*y,0.25);
re = Math.cos(0.5*Math.atan2(y,x))*factor;
im = Math.sin(0.5*Math.atan2(y,x))*factor;
return new Complex(re,im);
}

var fixedpts = function(a,b,c,d){
fp = [1000,1000];
ad = a.add(new Complex(-1,0).multiply(d));
discr = ad.multiply(ad).add(new Complex(4,0).multiply(b).multiply(c));
den = new Complex(2,0).multiply(c).reciprocal();
fp[0] = ad.add(cpxSqrt(discr)).multiply(den);
fp[1] = ad.add(cpxSqrt(discr).multiply(new Complex(-1,0))).multiply(den);
return fp;
}

remap = function(x,a,b,c,d){
//maps x from [a,b] to [c,d]
return (x - a) * (d - c) / (b - a) + c;
Expand Down

0 comments on commit 4011ffe

Please sign in to comment.