Skip to content

Commit 2b5e358

Browse files
committed
Adicionado funcao para um plot no modelo novo
1 parent 5951889 commit 2b5e358

File tree

3 files changed

+188
-6
lines changed

3 files changed

+188
-6
lines changed

src/main.cc

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,41 @@ int main()
77
{
88
Matrix matrix = Matrix(200, 2);
99

10+
11+
Matrix matrix_x = Matrix(200,1);
12+
Matrix matrix_y = Matrix(200,1);
1013
//Inicialização teste;
1114
for (int i=1; i <= 200; i++)
1215
{
13-
1416
float xCoord = (float) (i -100)/10;
1517

16-
matrix.add(i, 1, xCoord); //Coordenada X
17-
matrix.add(i, 2, sin(2*xCoord) + cos(xCoord)); //Coordenada Y
18+
matrix_x.add(i, 1, xCoord);
19+
matrix_y.add(i, 1, sin(2*xCoord) + cos(xCoord));
1820
}
1921

2022
//Instanciando plotter
21-
MatrixPlot matrixplot = MatrixPlot(2, 2); //Define subplot Cols; subplot Rows;
23+
//MatrixPlot matrixplot = MatrixPlot(2, 2); //Define subplot Cols; subplot Rows;
24+
25+
MatrixPlot matrixplot = MatrixPlot();
26+
matrixplot.plot1d(matrix_x, matrix_y);
27+
cout << "Depois do plot" << endl;
28+
//Matrix matrix_box = Matrix(10,2);
29+
30+
//matrixplot.plotbox(matrix);
2231

2332
//Plotando matrix 1d
33+
/*
2434
matrixplot.plot1d(matrix, 0); //Plota e define o indice do subplot
2535
matrixplot.plot1d(matrix, 1);
2636
matrixplot.plot1d(matrix, 2);
2737
matrixplot.plot1d(matrix, 3);
28-
29-
38+
*/
3039
matrixplot.Run();
3140

3241
return 0;
3342
}
43+
44+
void testSimulation()
45+
{
46+
47+
}

src/matrix-plot.cc

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,171 @@ void MatrixPlot::plot1d(Matrix & referenceMatrix, int subplotIndex){
119119

120120
}
121121

122+
void MatrixPlot::plot1d(Matrix & xMatrix, Matrix & yMatrix){
123+
124+
if (xMatrix.getRows() != yMatrix.getRows() && xMatrix.getCols() != yMatrix.getCols())
125+
cerr << "Matrizes de coordenadas incompativeis. Encerrando aplicativo";
126+
127+
int matrixPlotRows = xMatrix.getRows();
128+
int subplotAmount = xMatrix.getCols();
129+
130+
mglData matrix_X_coordinates(matrixPlotRows);
131+
mglData matrix_Y_coordinates(matrixPlotRows);
132+
133+
range matrixRange;
134+
135+
float matrixDataPoint;
136+
for (int subplotIndex=0; subplotIndex < subplotAmount; subplotIndex++)
137+
{
138+
for (int matrixPlotRowIndex=0; matrixPlotRowIndex < matrixPlotRows; matrixPlotRowIndex++)
139+
{
140+
float x = xMatrix.getMat((matrixPlotRowIndex+1), (subplotIndex+1));
141+
float y = yMatrix.getMat((matrixPlotRowIndex+1), (subplotIndex+1));
142+
143+
matrix_X_coordinates.a[matrixPlotRowIndex] = x;
144+
matrix_Y_coordinates.a[matrixPlotRowIndex] = y;
145+
146+
//minMax x
147+
try {
148+
if (x < matrixRange.x_min)
149+
matrixRange.x_min = x;
150+
} catch (...) {
151+
matrixRange.x_min = x;
152+
}
153+
154+
try {
155+
if (x > matrixRange.x_max)
156+
matrixRange.x_max = x;
157+
} catch (...) {
158+
matrixRange.x_max = x;
159+
}
160+
161+
//minMax y
162+
//minMax x
163+
try {
164+
if (y < matrixRange.y_min)
165+
matrixRange.y_min = y;
166+
} catch (...) {
167+
matrixRange.y_min = y;
168+
}
169+
170+
try {
171+
if (y > matrixRange.y_max)
172+
matrixRange.y_max = y;
173+
} catch (...) {
174+
matrixRange.y_max = y;
175+
}
176+
}
177+
178+
this->SetOrigin(0,0,0);
179+
180+
//Subplotagem
181+
182+
this->SubPlot(
183+
this->subplotCols,
184+
this->subplotRows,
185+
0, "");
186+
187+
this->Axis("xy");
188+
189+
if (this->autoRange)
190+
{
191+
this->SetRange('x', matrixRange.x_min, matrixRange.x_max);
192+
this->SetRange('y', matrixRange.y_min, matrixRange.y_max);
193+
}
194+
195+
this->Plot(matrix_X_coordinates, matrix_Y_coordinates);
196+
}
197+
198+
199+
}
200+
201+
void MatrixPlot::plotbox(Matrix & referenceMatrix, int subplotIndex)
202+
{
203+
int matrixRows = referenceMatrix.getRows();
204+
int matrixCols = referenceMatrix.getCols();
205+
206+
mglData matrix_X_coordinates(matrixRows);
207+
mglData matrix_Y_coordinates(matrixRows);
208+
209+
range matrixRange;
210+
211+
float matrixData[matrixRows][matrixCols];
212+
213+
for (int i=0; i < matrixRows; i++)
214+
{
215+
216+
for (int j=0; j < matrixCols; j++)
217+
{
218+
float dataPoint = referenceMatrix.getMat(i+1,j+1);
219+
220+
if (j == 0)
221+
{
222+
223+
//Min_x
224+
try {
225+
if (dataPoint < matrixRange.x_min)
226+
matrixRange.x_min = dataPoint;
227+
} catch (...) {
228+
matrixRange.x_min = dataPoint;
229+
}
230+
231+
//Max_x
232+
try {
233+
if (dataPoint > matrixRange.x_max)
234+
matrixRange.x_max = dataPoint;
235+
} catch (...) {
236+
matrixRange.x_max = dataPoint;
237+
}
238+
239+
240+
matrix_X_coordinates.a[i] = dataPoint;
241+
}
242+
else
243+
{
244+
//Min_x
245+
try {
246+
if (dataPoint < matrixRange.y_min)
247+
matrixRange.y_min = dataPoint;
248+
} catch (...) {
249+
matrixRange.y_min = dataPoint;
250+
}
251+
252+
//Max_x
253+
try {
254+
if (dataPoint > matrixRange.y_max)
255+
matrixRange.y_max = dataPoint;
256+
} catch (...) {
257+
matrixRange.y_max = dataPoint;
258+
}
259+
260+
matrix_Y_coordinates.a[i] = dataPoint;
261+
}
262+
263+
}
264+
265+
}
266+
267+
this->SetOrigin(0,0,0);
268+
269+
//Subplotagem
270+
271+
this->SubPlot(
272+
this->subplotCols,
273+
this->subplotRows,
274+
subplotIndex, "");
275+
276+
this->Axis("xy");
277+
278+
if (this->autoRange)
279+
{
280+
this->SetRange('x', matrixRange.x_min, matrixRange.x_max);
281+
this->SetRange('y', matrixRange.y_min, matrixRange.y_max);
282+
}
283+
284+
this->Plot(matrix_X_coordinates, matrix_Y_coordinates);
285+
}
286+
122287
void MatrixPlot::setAutoRange(bool option)
123288
{
124289
this->autoRange = option;

src/matrix-plot.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class MatrixPlot : public mglFLTK
3131
MatrixPlot(int subplotCols = 1, int subplotRows = 1);
3232

3333
void plot1d(Matrix &, int = 0);
34+
void plot1d(Matrix &, Matrix &);
35+
36+
void plotbox(Matrix &, int = 0);
3437

3538
void setAutoRange(bool);
3639

0 commit comments

Comments
 (0)