-
Notifications
You must be signed in to change notification settings - Fork 0
/
cutCornersSymmetric.js
107 lines (83 loc) · 3.52 KB
/
cutCornersSymmetric.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
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
"use strict";
// same as poincareDisc, but cutting corners
// beware: use (k 2 n) triangles
var cutCornersSymmetric={};
// parameters
cutCornersSymmetric.scale=20;
cutCornersSymmetric.setup=function(center,left,right){
// rotational symmetry at center
cutCornersSymmetric.nSymmCenter=center;
//poincare circle and plane
// rotational symmetry at left corner is always 2
cutCornersSymmetric.nSymmLeft=left;
// rotational symmetry at right corner
cutCornersSymmetric.nSymmRight=right;
// angles
var alpha=Math.PI/cutCornersSymmetric.nSymmLeft;
var beta=Math.PI/cutCornersSymmetric.nSymmRight;
var gamma=Math.PI/cutCornersSymmetric.nSymmCenter;
// poincare disc
// intersection of straight lines with unit circle (radius=1)
// find position of unit circle
cutCornersSymmetric.yCenterCircle=Math.cos(alpha);
cutCornersSymmetric.xCenterCircle=(Math.cos(alpha)*Math.cos(gamma)+Math.cos(beta))/Math.sin(gamma);
var r2=cutCornersSymmetric.xCenterCircle*cutCornersSymmetric.xCenterCircle+cutCornersSymmetric.yCenterCircle*cutCornersSymmetric.yCenterCircle;
var worldRadius=Math.sqrt(r2-1);
// rescale world radius to be 0.5
cutCornersSymmetric.rCircle=0.5/worldRadius;
cutCornersSymmetric.yCenterCircle*=0.5/worldRadius;
cutCornersSymmetric.xCenterCircle*=0.5/worldRadius;
//world radius is now 0.5
console.log("xcc "+cutCornersSymmetric.xCenterCircle);
console.log("radiuscc "+cutCornersSymmetric.rCircle);
console.log("basic triangle border at x-axis "+(cutCornersSymmetric.xCenterCircle-cutCornersSymmetric.rCircle));
console.log(cutCornersDouble.yCenterCircle);
// distance of center of basic mirror cutCornersDouble.xCenterCircle with radius cutCornersDouble.rCircle
worldRadius=0.5;
console.log("offset "+delta);
// a hack
var dBase=Math.sqrt(r2);
var delta=dBase-cutCornersSymmetric.rCircle;
var dAdd=(worldRadius*worldRadius+delta*delta)/2/delta/Math.cos(gamma/2);
cutCornersSymmetric.xCenterAdd1=dAdd*Math.cos(gamma);
cutCornersSymmetric.yCenterAdd1=dAdd*Math.sin(gamma);
cutCornersSymmetric.xCenterAdd2=dAdd;
cutCornersSymmetric.yCenterAdd2=0;
cutCornersSymmetric.rAdd=Math.sqrt(dAdd*dAdd-worldRadius*worldRadius);
console.log(" rAdd "+cutCornersSymmetric.rAdd);
}
// poincare disc
// colorposition: 0 if no mapping, else parity
cutCornersSymmetric.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(cutCornersSymmetric.nSymmCenter);
iter++;
if (iter>iterMax){
return false;
}
if (inputImagePosition.circleInversionInsideOut(cutCornersSymmetric.xCenterCircle,cutCornersSymmetric.yCenterCircle,cutCornersSymmetric.rCircle)){
isFinished=false;
colorPosition.x++;
}
else { // basic mirroring finished, point is inside basic triangle, additional mirrors
if (inputImagePosition.circleInversionInsideOut(cutCornersSymmetric.xCenterAdd1,cutCornersSymmetric.yCenterAdd1,cutCornersSymmetric.rAdd)){
colorPosition.x++;
}
if (inputImagePosition.circleInversionInsideOut(cutCornersSymmetric.xCenterAdd2,cutCornersSymmetric.yCenterAdd2,cutCornersSymmetric.rAdd)){
colorPosition.x++;
}
}
}
basicRosette(inputImagePosition,cutCornersSymmetric.nSymmCenter);
inputImagePosition.scale(cutCornersSymmetric.scale);
return true;
}