N
N
NORM2020-12-01 15:42:55
C++ / C#
NORM, 2020-12-01 15:42:55

How to shade the area of ​​intersection of two functions in SFML?

Task: Given a curvilinear trapezoid bounded by two intersecting lines - f1(x) and f2(x). Find the abscissas of the intersection points of these lines (a,b). Display graphs of these lines in graphics mode, specifying the appropriate labels. Color the area of ​​the trapezium formed by the lines.
f1(x)= x*x, f2(x)= cos(x), blue.

I made a display of two functions, but I don’t know how to paint over the area of ​​\u200b\u200btheir intersection.

#include <cmath>
#include <SFML/Graphics.hpp>
using namespace sf;
int main()
{
  const int SIZE = 600;
  float h = 0.5;
  float x = -100;
  int zoom = 30;
  RenderWindow window(VideoMode(SIZE, SIZE),"lab11");
  VertexArray line1(LinesStrip, SIZE);
  VertexArray line2(LinesStrip, SIZE);
  for (int i = 0; i<SIZE; i++, x += h)
  {
    line1[i].position = Vector2f(SIZE / 2 + x*zoom, SIZE / 2 - x * x*zoom);
    line1[i].color = Color::White;		
    line2[i].position = Vector2f(SIZE / 2 + x * zoom, SIZE / 2 - cos(x) * zoom);
    line2[i].color = Color::Green;
  }
  while (window.isOpen())
  {
    Event event;
    while (window.pollEvent(event))
      if (event.type == Event::Closed)
        window.close();
    window.clear();
    window.draw(line1);
    window.draw(line2);
    window.display();
  }
}

5fc63a01be549690851008.png
You can use any graphics library, but I already did a few SFML labs and everything was fine.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NORM, 2020-12-02
@NORMgg

I asked the question, I'll answer it myself. SFML does not have a function to fill like graphics.h - floodfill(). People on the forums write that it is not difficult to implement it yourself using this algorithm .
How to write this algorithm in C++?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question