|
@@ -106,30 +106,30 @@ En este ejercicio graficarás algunas ecuaciones paramétricas que generan curva
|
106
|
106
|
|
107
|
107
|
3. El archivo `main.cpp` (en Sources) contiene la función `main()` donde estarás añadiendo código. Abre ese archivo y estudia el código.
|
108
|
108
|
|
109
|
|
- ```
|
110
|
|
- QApplication a(argc, argv);
|
111
|
|
- XYPlotWindow wLine;
|
112
|
|
- XYPlotWindow wCircle;
|
113
|
|
- XYPlotWindow wHeart;
|
114
|
|
- XYPlotWindow wButterfly;
|
115
|
|
-
|
116
|
|
- double y = 0.00;
|
117
|
|
- double x = 0.00;
|
118
|
|
- double increment = 0.01;
|
119
|
|
-
|
120
|
|
- for (double t = 0; t < 2*M_PI; t = t + increment) {
|
121
|
|
- // parametric equations
|
122
|
|
- x = t;
|
123
|
|
- y = t;
|
124
|
|
-
|
125
|
|
- // add x and y as a point in the graph
|
126
|
|
- wLine.AddPointToGraph(x,y);
|
127
|
|
- }
|
128
|
|
-
|
129
|
|
- // After all the points have been added, plot and show the graph
|
130
|
|
- wLine.Plot();
|
131
|
|
- wLine.show();
|
132
|
|
- ```
|
|
109
|
+
|
|
110
|
+ QApplication a(argc, argv);
|
|
111
|
+ XYPlotWindow wLine;
|
|
112
|
+ XYPlotWindow wCircle;
|
|
113
|
+ XYPlotWindow wHeart;
|
|
114
|
+ XYPlotWindow wButterfly;
|
|
115
|
+
|
|
116
|
+ double y = 0.00;
|
|
117
|
+ double x = 0.00;
|
|
118
|
+ double increment = 0.01;
|
|
119
|
+
|
|
120
|
+ for (double t = 0; t < 2*M_PI; t = t + increment) {
|
|
121
|
+ // parametric equations
|
|
122
|
+ x = t;
|
|
123
|
+ y = t;
|
|
124
|
+
|
|
125
|
+ // add x and y as a point in the graph
|
|
126
|
+ wLine.AddPointToGraph(x,y);
|
|
127
|
+ }
|
|
128
|
+
|
|
129
|
+ // After all the points have been added, plot and show the graph
|
|
130
|
+ wLine.Plot();
|
|
131
|
+ wLine.show();
|
|
132
|
+
|
133
|
133
|
|
134
|
134
|
La línea `XYPlotWindow wLine;` crea el objeto `wLine` que será la ventana en donde se dibujará una gráfica, en este caso la gráfica de un segmento. Observa el ciclo `for`. En este ciclo se genera una serie de valores para $t$ y se computa un valor de $x$ y $y$ para cada valor de $t$. Cada par ordenado $(x,y)$ es añadido a la gráfica del segmento por el método `AddPointToGraph(x,y)`. Luego del ciclo se invoca el método `Plot()`, que "dibuja" los puntos, y el método `show()`, que muestra la gráfica. Los *métodos* son funciones que nos permiten trabajar con los datos de los objetos. Nota que cada uno de los métodos se escribe luego de `wLine`, seguido de un punto. En una experiencia de laboratorio posterior aprenderás más sobre objetos y practicarás cómo crearlos e invocar sus métodos.
|
135
|
135
|
|
|
@@ -309,30 +309,30 @@ You can also download the folder `Expressions-PrettyPlots` from `http://bitbuck
|
309
|
309
|
|
310
|
310
|
3. The file `main.cpp` (in Sources) contains the function `main()` where you will be adding code. Open this file and study the code.
|
311
|
311
|
|
312
|
|
- ```cpp
|
313
|
|
- QApplication a(argc, argv);
|
314
|
|
- XYPlotWindow wLine;
|
315
|
|
- XYPlotWindow wCircle;
|
316
|
|
- XYPlotWindow wHeart;
|
317
|
|
- XYPlotWindow wButterfly;
|
318
|
|
-
|
319
|
|
- double y = 0.00;
|
320
|
|
- double x = 0.00;
|
321
|
|
- double increment = 0.01;
|
322
|
|
-
|
323
|
|
- for (double t = 0; t < 2*M_PI; t = t + increment) {
|
324
|
|
- // parametric equations
|
325
|
|
- x = t;
|
326
|
|
- y = t;
|
327
|
|
-
|
328
|
|
- // add x and y as a point in the graph
|
329
|
|
- wLine.AddPointToGraph(x,y);
|
330
|
|
- }
|
331
|
|
-
|
332
|
|
- // After all the points have been added, plot and show the graph
|
333
|
|
- wLine.Plot();
|
334
|
|
- wLine.show();
|
335
|
|
- ```
|
|
312
|
+
|
|
313
|
+ QApplication a(argc, argv);
|
|
314
|
+ XYPlotWindow wLine;
|
|
315
|
+ XYPlotWindow wCircle;
|
|
316
|
+ XYPlotWindow wHeart;
|
|
317
|
+ XYPlotWindow wButterfly;
|
|
318
|
+
|
|
319
|
+ double y = 0.00;
|
|
320
|
+ double x = 0.00;
|
|
321
|
+ double increment = 0.01;
|
|
322
|
+
|
|
323
|
+ for (double t = 0; t < 2*M_PI; t = t + increment) {
|
|
324
|
+ // parametric equations
|
|
325
|
+ x = t;
|
|
326
|
+ y = t;
|
|
327
|
+
|
|
328
|
+ // add x and y as a point in the graph
|
|
329
|
+ wLine.AddPointToGraph(x,y);
|
|
330
|
+ }
|
|
331
|
+
|
|
332
|
+ // After all the points have been added, plot and show the graph
|
|
333
|
+ wLine.Plot();
|
|
334
|
+ wLine.show();
|
|
335
|
+
|
336
|
336
|
|
337
|
337
|
The line `XYPlotWindow wLine;` creates the object `wLine`, that is the window that will show the plot of a graph, in this case the graph of a segment. Look at the `for` cycle. In this cycle several values for $t$ are generated and a value for $x$ and $y$ is computed for each $t$. Each ordered pair $(x,y)$ is added to the graph of the segment by the method `AddPointToGraph(x,y)`. After the cycle, there is a call to the method `Plot()`, to "draw" the points in the graph, and to the method `show()`, to show the plot. The *methods* are functions that allow us to work with the data of an object. Note that each of the methods is written after `wLine`, and followed by a period. In a future laboratory experience you will learn more about objects and practice how to create them and invoke their methods.
|
338
|
338
|
|