Skip to content

Commit bb93744

Browse files
committed
command for env setup & tiny changes for shapely compatible
1 parent f97aff2 commit bb93744

File tree

4 files changed

+219
-4
lines changed

4 files changed

+219
-4
lines changed

GeoGebra3dTo2D.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,14 @@ def SplitLines(sgLine2dList, sgPolygon2dList, npLine3dList, npPolygon3dList, T,
281281
lineIntersectionsList = []
282282
for i in range(len(sgLine2dList)):
283283
sgLine2d = sgLine2dList[i]
284-
intersectionsList = sgLine2d.coords._coords.tolist()
284+
# remove _coords to fit for different version of shapely
285+
# intersectionsList = sgLine2d.coords._coords.tolist()
286+
intersectionsList = np.array(sgLine2d.coords).tolist()
285287
for j in range(len(sgPolygon2dList)):
286288
sgPolygon = sgPolygon2dList[j]
287289
if sgPolygon.intersects(sgLine2d):
288290
intersections = sgPolygon.intersection(sgLine2d)
289-
intersectionsList.extend(intersections.coords._coords.tolist())
291+
intersectionsList.extend(np.array(intersections.coords).tolist())
290292

291293
intersection3d = Calculate3dIntersection(npLine3dList[i], npPolygon3dList[j])
292294
if intersection3d is not None:

README.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,29 @@
33
a script helps to export svg for Geogebra 3d calculator.
44
[Geogebra 3d calculator](https://www.geogebra.org/3d) is an excellent app for 3d graph. But we cannot export the final result to svg file. This script can parse the project file (.ggb) and convert to a set of Geogebra commands which you can load to [Geogebra geometry](https://www.geogebra.org/geometry), then you can export to svg file from Geogebra geometry.
55

6+
# Environment setup
7+
You can use anaconda to setup environment.
8+
```
9+
conda create -n Your_environment_name python=Your_Python_Version
10+
conda activate Your_environment_name
11+
conda install -c anaconda numpy -y
12+
conda install -c conda-forge shapely -y
13+
```
14+
Or you can simply do like this:
15+
```
16+
conda env create -f environment.yml
17+
conda activate Geogebra
18+
```
19+
620
# Usage
721
```python
822
python ./GeoGebra3dTo2D.py --dataLocation=./data/OGLCoor_zn.ggb
923
```
1024
The script will create a folder with your file name (OGLCoor_zn in example) and you can see "commandList.txt" under that folder. Copy the content of "commandList.txt" and paste to [Geogebra geometry](https://www.geogebra.org/geometry).
25+
./data/OGLCoor_zn.ggb and ./data/commandList.txt are provided for test.
1126

1227
# Limitation
13-
- I only support "Segment", "Vector", "Polygon" in the graph, will add "Ray", "Line" soon.
28+
- I only support "Segment", "Vector", "Polygon" and "Point" in the graph, will add "Ray", "Line" later.
1429
- Text command from Geogebra failed to support Latex format, so the script didn't create related text to Geogebra geometry. But you can manually create them.
1530

1631
# Example
@@ -22,5 +37,5 @@ Download the ggb file.
2237
- Step 3
2338
Run the script.
2439
- Step 4
25-
Open "commandList.txt" and copy all commands. Visit [Geogebra geometry](https://www.geogebra.org/geometry) and create a button (or you can just create a point), right click and go to "Scripting" tab, paste all commands there. Click the button (or the point). Then you can see:
40+
Open "commandList.txt" and copy all commands. Visit [Geogebra geometry](https://www.geogebra.org/geometry) and create a button (or you can just create a point anywhere), right click and go to "Scripting" tab, paste all commands there. Click the button (or the point). Then you can see:
2641
![](imgs/OGLCoor_zn.svg "axis z negative")

data/commandList.txt

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
A0 = Segment((-6.91, 4.09), (-2.52, 2.51))
2+
A1 = Segment((-2.52, 2.51), (-2.53, -7.08))
3+
A10 = Segment((2.75, 3.43), (0.55, 1.15))
4+
A11 = Segment((0.55, 1.15), (-2.52, -2.04))
5+
A12 = Segment((-2.52, -2.04), (-4.72, -4.32))
6+
A13 = Segment((7.36, 0.53), (4.95, 0.26))
7+
A14 = Segment((4.95, 0.26), (4.06, 0.15))
8+
A15 = Segment((4.06, 0.15), (0.54, -0.24))
9+
A16 = Segment((0.54, -0.24), (-2.52, -0.59))
10+
A17 = Segment((-2.52, -0.59), (-6.03, -0.98))
11+
A2 = Segment((-2.53, -7.08), (-6.86, -5.34))
12+
A20 = Vector((2.73, 0.63), (2.75, 3.43))
13+
A21 = Vector((2.73, 0.63), (4.06, 0.15))
14+
A22 = Vector((-4.73, -1.48), (-4.72, -4.32))
15+
A23 = Vector((-4.73, -1.48), (-6.03, -0.98))
16+
A24 = Vector((5.13, 1.31), (5.18, 5.96))
17+
A25 = Vector((5.13, 1.31), (7.36, 0.53))
18+
A26 = Vector((-0.96, -5.08), (-0.94, 4.32))
19+
A27 = Segment((-6.3, 1.56), (-2.52, 0.17))
20+
A28 = Segment((-2.52, 0.17), (0.54, -0.96))
21+
A29 = Segment((0.54, -0.96), (4.92, -2.58))
22+
A3 = Segment((-6.86, -5.34), (-6.91, 4.09))
23+
A30 = Vector((4.92, -2.58), (5.81, -2.91))
24+
A31 = Segment((6.32, 1.65), (4.96, 1.26))
25+
A32 = Segment((4.96, 1.26), (2.73, 0.63))
26+
A33 = Segment((2.73, 0.63), (0.54, 0.01))
27+
A34 = Segment((0.54, 0.01), (-2.52, -0.86))
28+
A35 = Segment((-2.52, -0.86), (-4.73, -1.48))
29+
A36 = Segment((-4.73, -1.48), (-6.88, -2.09))
30+
A37 = Vector((-6.88, -2.09), (-7.3, -2.21))
31+
A4 = Segment((4.9, -4.83), (0.53, -3.17))
32+
A5 = Segment((0.53, -3.17), (0.57, 6.06))
33+
A6 = Segment((0.57, 6.06), (5.0, 4.55))
34+
A7 = Segment((5.0, 4.55), (4.9, -4.83))
35+
A8 = Segment((5.18, 5.96), (4.12, 4.85))
36+
A9 = Segment((4.12, 4.85), (2.75, 3.43))
37+
AP18 = Polygon((-6.91, 4.09), (-2.52, 2.51), (-2.53, -7.08), (-6.86, -5.34), (-6.91, 4.09))
38+
AP19 = Polygon((4.9, -4.83), (0.53, -3.17), (0.57, 6.06), (5.0, 4.55), (4.9, -4.83))
39+
AP38 = ((5.18, 5.96))
40+
AP39 = ((-4.72, -4.32))
41+
AP40 = ((2.75, 3.43))
42+
Export_1 = ((-7.3, 6.06))
43+
Export_2 = ((7.36, -7.08))
44+
SetColor(A0, 0.08235294117647059, 0.396078431372549, 0.7529411764705882)
45+
SetColor(A1, 0.08235294117647059, 0.396078431372549, 0.7529411764705882)
46+
SetColor(A10, 0.1803921568627451, 0.49019607843137253, 0.19607843137254902)
47+
SetColor(A11, 0.1803921568627451, 0.49019607843137253, 0.19607843137254902)
48+
SetColor(A12, 0.1803921568627451, 0.49019607843137253, 0.19607843137254902)
49+
SetColor(A13, 0.8274509803921568, 0.1843137254901961, 0.1843137254901961)
50+
SetColor(A14, 0.8274509803921568, 0.1843137254901961, 0.1843137254901961)
51+
SetColor(A15, 0.8274509803921568, 0.1843137254901961, 0.1843137254901961)
52+
SetColor(A16, 0.8274509803921568, 0.1843137254901961, 0.1843137254901961)
53+
SetColor(A17, 0.8274509803921568, 0.1843137254901961, 0.1843137254901961)
54+
SetColor(A2, 0.08235294117647059, 0.396078431372549, 0.7529411764705882)
55+
SetColor(A20, 0.1803921568627451, 0.49019607843137253, 0.19607843137254902)
56+
SetColor(A21, 0.8274509803921568, 0.1843137254901961, 0.1843137254901961)
57+
SetColor(A22, 0.1803921568627451, 0.49019607843137253, 0.19607843137254902)
58+
SetColor(A23, 0.8274509803921568, 0.1843137254901961, 0.1843137254901961)
59+
SetColor(A24, 0.1803921568627451, 0.49019607843137253, 0.19607843137254902)
60+
SetColor(A25, 0.8274509803921568, 0.1843137254901961, 0.1843137254901961)
61+
SetColor(A26, 0.0, 0.8, 0.0)
62+
SetColor(A27, 0.8274509803921568, 0.1843137254901961, 0.1843137254901961)
63+
SetColor(A28, 0.8274509803921568, 0.1843137254901961, 0.1843137254901961)
64+
SetColor(A29, 0.8274509803921568, 0.1843137254901961, 0.1843137254901961)
65+
SetColor(A3, 0.08235294117647059, 0.396078431372549, 0.7529411764705882)
66+
SetColor(A30, 0.8274509803921568, 0.1843137254901961, 0.1843137254901961)
67+
SetColor(A31, 0.0, 0.2, 0.8)
68+
SetColor(A32, 0.0, 0.2, 0.8)
69+
SetColor(A33, 0.0, 0.2, 0.8)
70+
SetColor(A34, 0.0, 0.2, 0.8)
71+
SetColor(A35, 0.0, 0.2, 0.8)
72+
SetColor(A36, 0.0, 0.2, 0.8)
73+
SetColor(A37, 0.0, 0.2, 0.8)
74+
SetColor(A4, 0.08235294117647059, 0.396078431372549, 0.7529411764705882)
75+
SetColor(A5, 0.08235294117647059, 0.396078431372549, 0.7529411764705882)
76+
SetColor(A6, 0.08235294117647059, 0.396078431372549, 0.7529411764705882)
77+
SetColor(A7, 0.08235294117647059, 0.396078431372549, 0.7529411764705882)
78+
SetColor(A8, 0.1803921568627451, 0.49019607843137253, 0.19607843137254902)
79+
SetColor(A9, 0.1803921568627451, 0.49019607843137253, 0.19607843137254902)
80+
SetColor(AP18, 0.08235294117647059, 0.396078431372549, 0.7529411764705882)
81+
SetColor(AP19, 0.08235294117647059, 0.396078431372549, 0.7529411764705882)
82+
SetColor(AP38, 0.3803921568627451, 0.3803921568627451, 0.3803921568627451)
83+
SetColor(AP39, 0.3803921568627451, 0.3803921568627451, 0.3803921568627451)
84+
SetColor(AP40, 0.3803921568627451, 0.3803921568627451, 0.3803921568627451)
85+
SetConditionToShowObject(Export_1, False)
86+
SetConditionToShowObject(Export_2, False)
87+
SetLineStyle(A0, 0)
88+
SetLineStyle(A1, 0)
89+
SetLineStyle(A10, 1)
90+
SetLineStyle(A11, 1)
91+
SetLineStyle(A12, 1)
92+
SetLineStyle(A13, 1)
93+
SetLineStyle(A14, 1)
94+
SetLineStyle(A15, 1)
95+
SetLineStyle(A16, 1)
96+
SetLineStyle(A17, 1)
97+
SetLineStyle(A2, 0)
98+
SetLineStyle(A20, 0)
99+
SetLineStyle(A21, 0)
100+
SetLineStyle(A22, 0)
101+
SetLineStyle(A23, 0)
102+
SetLineStyle(A24, 0)
103+
SetLineStyle(A25, 0)
104+
SetLineStyle(A26, 0)
105+
SetLineStyle(A27, 1)
106+
SetLineStyle(A28, 0)
107+
SetLineStyle(A29, 0)
108+
SetLineStyle(A3, 0)
109+
SetLineStyle(A30, 0)
110+
SetLineStyle(A31, 0)
111+
SetLineStyle(A32, 1)
112+
SetLineStyle(A33, 0)
113+
SetLineStyle(A34, 0)
114+
SetLineStyle(A35, 1)
115+
SetLineStyle(A36, 0)
116+
SetLineStyle(A37, 0)
117+
SetLineStyle(A4, 0)
118+
SetLineStyle(A5, 0)
119+
SetLineStyle(A6, 0)
120+
SetLineStyle(A7, 0)
121+
SetLineStyle(A8, 1)
122+
SetLineStyle(A9, 1)
123+
SetLineStyle(AP18, 0)
124+
SetLineStyle(AP19, 0)
125+
SetLineThickness(A0, 2)
126+
SetLineThickness(A1, 2)
127+
SetLineThickness(A10, 3)
128+
SetLineThickness(A11, 3)
129+
SetLineThickness(A12, 3)
130+
SetLineThickness(A13, 3)
131+
SetLineThickness(A14, 3)
132+
SetLineThickness(A15, 3)
133+
SetLineThickness(A16, 3)
134+
SetLineThickness(A17, 3)
135+
SetLineThickness(A2, 2)
136+
SetLineThickness(A20, 4)
137+
SetLineThickness(A21, 4)
138+
SetLineThickness(A22, 4)
139+
SetLineThickness(A23, 4)
140+
SetLineThickness(A24, 4)
141+
SetLineThickness(A25, 4)
142+
SetLineThickness(A26, 3)
143+
SetLineThickness(A27, 3)
144+
SetLineThickness(A28, 3)
145+
SetLineThickness(A29, 3)
146+
SetLineThickness(A3, 2)
147+
SetLineThickness(A30, 3)
148+
SetLineThickness(A31, 3)
149+
SetLineThickness(A32, 3)
150+
SetLineThickness(A33, 3)
151+
SetLineThickness(A34, 3)
152+
SetLineThickness(A35, 3)
153+
SetLineThickness(A36, 3)
154+
SetLineThickness(A37, 3)
155+
SetLineThickness(A4, 2)
156+
SetLineThickness(A5, 2)
157+
SetLineThickness(A6, 2)
158+
SetLineThickness(A7, 2)
159+
SetLineThickness(A8, 3)
160+
SetLineThickness(A9, 3)
161+
SetLineThickness(AP18, 2)
162+
SetLineThickness(AP19, 2)
163+
SetPointSize(AP38, 3)
164+
SetPointSize(AP39, 3)
165+
SetPointSize(AP40, 3)
166+
ShowLabel(AP38, False)
167+
ShowLabel(AP39, False)
168+
ShowLabel(AP40, False)
169+
ShowLabel(Export_1, False)
170+
ShowLabel(Export_2, False)

environment.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Geogebra
2+
channels:
3+
- conda-forge
4+
- anaconda
5+
- defaults
6+
dependencies:
7+
- blas=1.0
8+
- ca-certificates=2022.4.26
9+
- certifi=2022.6.15
10+
- geos=3.10.2
11+
- intel-openmp=2021.4.0
12+
- mkl=2021.4.0
13+
- mkl-service=2.4.0
14+
- mkl_fft=1.3.1
15+
- mkl_random=1.2.2
16+
- numpy=1.22.3
17+
- numpy-base=1.22.3
18+
- openssl=1.1.1s
19+
- pip=22.3.1
20+
- python=3.9.16
21+
- python_abi=3.9
22+
- setuptools=65.6.3
23+
- shapely=1.8.1
24+
- six=1.16.0
25+
- sqlite=3.40.1
26+
- tzdata=2022g
27+
- wheel=0.37.1
28+
- wincertstore=0.2

0 commit comments

Comments
 (0)