-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElliptic-Curve-Visualization_Export-Experiment-Rotate2.wl
150 lines (136 loc) · 4.62 KB
/
Elliptic-Curve-Visualization_Export-Experiment-Rotate2.wl
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
138
139
140
141
142
143
144
145
146
147
148
149
150
(* ::Package:: *)
EllipticCurvePointsModP[p_, a_, b_] := Module[{points = {}, y2EC, yEC},
For[x = 0, x < p, x++, y2EC = Mod[x^3 + a*x + b, p];
If[MemberQ[Table[Mod[i^2, p], {i, p}], y2EC],
yEC = Select[Range[0, p - 1], Mod[#^2, p] == y2EC &];
points = Join[points, {x, #} & /@ yEC];];
];
points
]
WeierstrassCurvePlot[iterations_, primes_, iterRev_] := Module[{c, a, p, xTorus, yTorus, zTorus, aCoeff, bCoeff, xElliptic, yElliptic, xMapped, yMapped, zMapped, fieldPoints, uMap, vMap, meshPoints, lines, labelPos, pointsOnCurve, mappedCurvePoints, myPlot, x, y, y2, i, revs},
(*Define radii of torus*)
c = 4;
a = 2;
p = primes;
(*Torus parametric functions*)
xTorus[u_, v_] = (c + a Cos[v]) Cos[u];
yTorus[u_, v_] = (c + a Cos[v]) Sin[u];
zTorus[u_, v_] = a Sin[v];
(*Elliptic curve parameters*)
aCoeff = 1;
bCoeff = 0;
(*Elliptic curve parametric functions*)
xElliptic[t_] = t;
yElliptic[t_] = Sqrt[t^3 + aCoeff*t + bCoeff];
(* Number of full revs *)
revs = Floor[iterations/iterRev];
(*Map the elliptic curve onto the torus*)
xMapped[pt_] := xTorus[uMap[pt[[1]]], vMap[pt[[2]]]];
yMapped[pt_] := yTorus[uMap[pt[[1]]], vMap[pt[[2]]]];
zMapped[pt_] := zTorus[uMap[pt[[1]]], vMap[pt[[2]]]];
(*Finite Field and Mesh Points*)
(*p = 17; (*Modulus*)*)
fieldPoints = Tuples[Range[0, p - 1], 2];
uMap[x_] := 2 Pi x/(p - 1) + Pi;
vMap[y_] := Pi (2 y/(p - 1) - 1) + Pi;
meshPoints = Map[Function[pt, {xTorus[uMap[pt[[1]]], vMap[pt[[2]]]], yTorus[uMap[pt[[1]]], vMap[pt[[2]]]], zTorus[uMap[pt[[1]]], vMap[pt[[2]]]]}], fieldPoints];
(*Generate lines for the mesh grid with translucent lines*)
lines = {};
For[i = 1, i <= p, i++,
For[j = 1, j < p, j++,
AppendTo[lines, {Directive[White, Opacity[0.3]], Line[{meshPoints[[p (i - 1) + j]], meshPoints[[p (i - 1) + j + 1]]}]}];
AppendTo[lines, {Directive[White, Opacity[0.3]], Line[{meshPoints[[p (j - 1) + i]], meshPoints[[p (j) + i]]}]}];
];
];
(*Define the label for the (0,0) point on the torus*)
labelPos = {xTorus[uMap[0], vMap[0]], yTorus[uMap[0], vMap[0]], zTorus[uMap[0], vMap[0]]};
i=1;
pointsOnCurve = EllipticCurvePointsModP[p, aCoeff, bCoeff];
mappedCurvePoints = Map[Function[pt, {xMapped[pt], yMapped[pt], zMapped[pt]}], pointsOnCurve];
numMappedCurvePoints = Length[mappedCurvePoints];
rotationAngle = iterations/10; (* Define your rotation angle here *)
(*Plotting*)
rotatedGraphics = Map[
Function[obj, Rotate[obj, rotationAngle, {0, 0, 1}]],
{(* All your graphics objects go here *)
ParametricPlot3D[
{xTorus[u, v], yTorus[u, v], zTorus[u, v]},
{u, 0, 2 Pi},
{v, -Pi, Pi},
PlotStyle -> Directive[White, Opacity[0.05]],
Mesh -> None,
Lighting -> "Neutral"
],
Graphics3D[
{
Directive[White],
PointSize[Small],
lines, (*existing graphics elements*)
Cyan,
PointSize[Medium],
Point[mappedCurvePoints]
},
],
(*Elliptic Curve # of Rev *)
If[revs > 0,
Table[
ParametricPlot3D[
{xMapped[{u, yElliptic[u]}], yMapped[{u, yElliptic[u]}], zMapped[{u, yElliptic[u]}]},
{u, (i - 1) * (p - 1), (i) * (p - 1)},
PlotStyle -> Directive[Cyan, Thickness[0.002]]
],
{i, 1, revs}
],
{} (* This is the output when revs <= 0 *)
],
If[revs > 0,
Table[
ParametricPlot3D[
{xMapped[{u, yElliptic[u]}], yMapped[{u, yElliptic[u]}], -zMapped[{u, yElliptic[u]}]},
{u, (i - 1) * (p - 1), (i) * (p - 1)},
PlotStyle -> Directive[Cyan, Thickness[0.002]]
],
{i, 1, revs}
],
{} (* This is the output when revs <= 0 *)
],
(*Elliptic Curve*)
If[Mod[iterations, iterRev] != 0,
ParametricPlot3D[
{xMapped[{u, yElliptic[u]}], yMapped[{u, yElliptic[u]}], zMapped[{u, yElliptic[u]}]},
{u, (revs) * (p - 1), (iterations * (p - 1)/iterRev)},
PlotStyle -> Directive[Cyan, Thickness[0.002]]
],
{}
],
If[Mod[iterations, iterRev] != 0,
ParametricPlot3D[
{xMapped[{u, yElliptic[u]}], yMapped[{u, yElliptic[u]}], -zMapped[{u, yElliptic[u]}]},
{u, (revs) * (p - 1), (iterations * (p - 1)/iterRev)},
PlotStyle -> Directive[Cyan, Thickness[0.002]]
],
{}
],
(*Line at x = 0*)
ParametricPlot3D[
{xTorus[Pi, v], yTorus[Pi, v], zTorus[Pi, v]},
{v, -Pi, Pi},
PlotStyle -> Directive[Magenta, Opacity[0.5], Thickness[0.003]]
],
(*Line at y = 0*)
ParametricPlot3D[
{xTorus[u, 0], yTorus[u, 0], zTorus[u, 0]},
{u, 0, 2 Pi},
PlotStyle -> Directive[Red, Opacity[0.5], Thickness[0.003]]
]
Boxed -> False,
Axes -> False,
Background -> Black,
ViewProjection -> "Orthographic",
ViewPoint -> {1.3, -2.4, 2.0}, (* Adjust this line *)
PlotRange -> All,
ImageSize -> {800, 800}
}
]
];
Show[rotatedGraphics]