Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. void CPlot2D::plot1(CDC& dc, bool drawOuterRect, bool drawInnerGrid, bool anis)//рисуем графики
  2. {
  3. // Устанавливает режим отображения контекста устройства. Определяет единицу измерения,
  4. // для преобразования единиц измерения пространства страницы в пространства устройства
  5.  
  6. if (anis == 0) dc.SetMapMode(MM_TEXT); // Логическая единица измерения отображается как один пиксель устройства
  7. CMatrix V(3), W(3);
  8. V(2) = 1;
  9. if (anis)
  10. {
  11. for (int i = 0; i < _converter.countRows(); i++)
  12. {
  13. for (int j = 0; j < _converter.countCols(); j++)
  14. {
  15. _converter(i, j) = 1;
  16. }
  17. }
  18. }
  19. // Оси
  20. if (drawOuterRect)
  21. {
  22. dc.Rectangle(_rectWindow);
  23. }
  24. // График
  25. if (drawInnerGrid)
  26. {
  27. CPen pen(_penAxis._style, _penAxis._width, _penAxis._color);//передаем параметры пера
  28. CPen* pOldPen = dc.SelectObject(&pen); // Выбираем перо в контекст памяти
  29. V(0) = 0; //по х 0
  30. V(1) = _rectWorld._top; //по у передается значение верхушки прямоугольника
  31. W = anis ? V : _converter * V; // Конвертируем в ОСК
  32.  
  33. V(0) = 0;
  34. V(1) = _rectWorld._bottom;
  35. W = anis ? V : _converter * V;
  36.  
  37. for (double i = 0; i < (_rectWindow.bottom - _rectWindow.top); i += 10)
  38. {
  39. dc.MoveTo(_rectWindow.left, _rectWindow.top + i);//ставим точку
  40. dc.LineTo(_rectWindow.right, _rectWindow.top + i);//рисуем линию
  41. }
  42. for (double i = 0; i < (_rectWindow.right - _rectWindow.left); i += 10)
  43. {
  44. dc.MoveTo(_rectWindow.left + i, _rectWindow.top);
  45. dc.LineTo(_rectWindow.left + i, _rectWindow.bottom);
  46. }
  47. dc.SelectObject(pOldPen);
  48. }
  49.  
  50. V(0) = _functionArgument(0);
  51. V(1) = _functionValue(0);
  52. W = anis ? V : _converter * V;
  53. // Передаем параметры пера
  54. CPen MyPen(_penLine._style, _penLine._width, _penLine._color);
  55. CPen* pOldPen = dc.SelectObject(&MyPen);//передаем в контекст для рисования перо
  56. if (anis)
  57. {
  58. double top = _functionValue.getMin();
  59. double bottom = _functionValue.getMax();
  60. double left = _functionArgument.getMin();
  61. double right = _functionArgument.getMax();
  62. int buffer = dc.SetMapMode(MM_ANISOTROPIC);//Логические единицы измерения отображаются произвольными единицами измерения с произвольно масштабируемыми осями
  63. dc.SetWindowOrg(left, top); //Устанавливает начало окна контекста устройства.
  64. dc.SetWindowExt(right - left, -(bottom - top));//размеры окна
  65. dc.SetViewportOrg(0, _rectWindow.bottom);//Устанавливает начало области просмотра контекста устройства
  66. dc.SetViewportExt(_rectWindow.right - _rectWindow.left, _rectWindow.bottom - _rectWindow.top);//размеры области просмотра
  67. dc.MoveTo((int)W(0), (int)W(1));//определяем начальную точку
  68. for (int i = 1; i < _functionArgument.countRows(); i++)
  69. {
  70. V(0) = _functionArgument(i);
  71. V(1) = _functionValue(i);
  72. W = anis ? V : _converter * V;
  73. dc.LineTo((int)W(0), (int)W(1)); //ведем линию
  74. }
  75. dc.SelectObject(pOldPen);//возвращаем контекст рисования
  76.  
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement