From 4011ffe430400a15ec8c20bf757e633ab6d53ea2 Mon Sep 17 00:00:00 2001 From: tbh12001 Date: Mon, 27 Nov 2017 10:42:30 -0500 Subject: [PATCH] Added fixed point drawing --- js/mobius.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/js/mobius.js b/js/mobius.js index 7b34080..4faa00b 100644 --- a/js/mobius.js +++ b/js/mobius.js @@ -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){ @@ -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); @@ -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;