Answer the question
In order to leave comments, you need to log in
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();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question