-
Notifications
You must be signed in to change notification settings - Fork 0
/
poincareDisc.js
executable file
·63 lines (55 loc) · 1.93 KB
/
poincareDisc.js
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
"use strict";
var poincareDisc={};
// parameters
poincareDisc.scale=20;
poincareDisc.setup=function(center,left,right){
// rotational symmetry at center
poincareDisc.nSymmCenter=center;
//poincare circle and plane
// rotational symmetry at left corner
poincareDisc.nSymmLeft=left;
// rotational symmetry at right corner
poincareDisc.nSymmRight=right;
// angles
var alpha=Math.PI/poincareDisc.nSymmLeft;
var beta=Math.PI/poincareDisc.nSymmRight;
var gamma=Math.PI/poincareDisc.nSymmCenter;
// poincare disc
// intersection of straight lines with unit circle (radius=1)
// find position of unit circle
poincareDisc.yCenterCircle=Math.cos(alpha);
poincareDisc.xCenterCircle=(Math.cos(alpha)*Math.cos(gamma)+Math.cos(beta))/Math.sin(gamma);
var r2=poincareDisc.xCenterCircle*poincareDisc.xCenterCircle+poincareDisc.yCenterCircle*poincareDisc.yCenterCircle;
var worldRadius=Math.sqrt(r2-1);
// rescale world radius to be 0.5
poincareDisc.rCircle=0.5/worldRadius;
poincareDisc.yCenterCircle*=0.5/worldRadius;
poincareDisc.xCenterCircle*=0.5/worldRadius;
}
// poincare disc
// colorposition: 0 if no mapping, else parity
poincareDisc.map=function(inputImagePosition,colorPosition,spacePosition,canvasPosition){
var isFinished=false;
var iter=0;
var iterMax=iterMaximum;
inputImagePosition.set(spacePosition);
colorPosition.x=0; // as parity for 2 colors
if ((inputImagePosition.radius2()>0.25)&&cutoff){
return false;
}
while (!isFinished){
isFinished=true;
colorPosition.x+=inputImagePosition.rotationMirrorSymmetry(poincareDisc.nSymmCenter);
iter++;
if (iter>iterMax){
return false;
}
if (inputImagePosition.circleInversionInsideOut(poincareDisc.xCenterCircle,poincareDisc.yCenterCircle,poincareDisc.rCircle)){
isFinished=false;
colorPosition.x++;
}
}
basicRosette(inputImagePosition,poincareDisc.nSymmCenter);
inputImagePosition.scale(poincareDisc.scale);
return true;
}