fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <cmath>
  5.  
  6. struct Point {
  7. double x, y;
  8. };
  9.  
  10. // Function to calculate the distance between two points
  11. double distance(const Point& a, const Point& b) {
  12. return std::sqrt(std::pow(a.x - b.x, 2) + std::pow(a.y - b.y, 2));
  13. }
  14.  
  15. // Main function
  16. int main() {
  17. // Define the points according to the problem statement
  18. Point O = {0, 0}; // Origin
  19. Point A = {-4, 7}; // Point on OA
  20. Point B = {5, 7}; // Point on OB
  21. Point P = {-1, 3}; // Point P inside angle AOB
  22.  
  23. // Calculate the radius for the arc, which is the distance from O to A
  24. double radius = distance(O, A);
  25.  
  26. // Placeholder points for the intersection points; You need specific geometric algorithms to find these
  27. Point E = {0, 0}; // Intersection on OA
  28. Point F = {0, 0}; // Intersection on OB
  29. Point G = {0, 0}; // Intersection on OE
  30. Point H = {0, 0}; // Intersection on OF
  31. Point C = {0, 0}; // Intersection on OA
  32. Point D = {0, 0}; // Intersection on OB
  33.  
  34. // Open an SVG file to output the construction
  35. std::ofstream svgFile("construction.svg");
  36. svgFile << "<svg viewBox='-10 -5 20 15' xmlns='http://w...content-available-to-author-only...3.org/2000/svg'>";
  37.  
  38. // Draw line OA and OB
  39. svgFile << "<line x1='" << O.x << "' y1='" << O.y << "' x2='" << A.x << "' y2='" << A.y << "' stroke='black'/>";
  40. svgFile << "<line x1='" << O.x << "' y1='" << O.y << "' x2='" << B.x << "' y2='" << B.y << "' stroke='black'/>";
  41.  
  42. // Draw arcs with center O and P
  43. svgFile << "<circle cx='" << O.x << "' cy='" << O.y << "' r='" << radius << "' fill='none' stroke='blue'/>";
  44. svgFile << "<circle cx='" << P.x << "' cy='" << P.y << "' r='" << radius << "' fill='none' stroke='green'/>";
  45.  
  46. // Draw points O, A, B, and P
  47. // ...
  48.  
  49. // Draw lines CP and DP
  50. // ...
  51.  
  52. // Draw line l through G and H (assuming that points G and H have been calculated)
  53. // ...
  54.  
  55. // End the SVG file
  56. svgFile << "</svg>";
  57. svgFile.close();
  58.  
  59. std::cout << "The construction diagram has been generated and saved to 'construction.svg'." << std::endl;
  60.  
  61. return 0;
  62. }
  63.  
Success #stdin #stdout 0s 5304KB
stdin
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>

struct Point {
    double x, y;
};

// Function to calculate the distance between two points
double distance(const Point& a, const Point& b) {
    return std::sqrt(std::pow(a.x - b.x, 2) + std::pow(a.y - b.y, 2));
}

// Main function
int main() {
    // Define the points according to the problem statement
    Point O = {0, 0}; // Origin
    Point A = {-4, 7}; // Point on OA
    Point B = {5, 7}; // Point on OB
    Point P = {-1, 3}; // Point P inside angle AOB

    // Calculate the radius for the arc, which is the distance from O to A
    double radius = distance(O, A);

    // Placeholder points for the intersection points; You need specific geometric algorithms to find these
    Point E = {0, 0}; // Intersection on OA
    Point F = {0, 0}; // Intersection on OB
    Point G = {0, 0}; // Intersection on OE
    Point H = {0, 0}; // Intersection on OF
    Point C = {0, 0}; // Intersection on OA
    Point D = {0, 0}; // Intersection on OB

    // Open an SVG file to output the construction
    std::ofstream svgFile("construction.svg");
    svgFile << "<svg viewBox='-10 -5 20 15' xmlns='http://w...content-available-to-author-only...3.org/2000/svg'>";

    // Draw line OA and OB
    svgFile << "<line x1='" << O.x << "' y1='" << O.y << "' x2='" << A.x << "' y2='" << A.y << "' stroke='black'/>";
    svgFile << "<line x1='" << O.x << "' y1='" << O.y << "' x2='" << B.x << "' y2='" << B.y << "' stroke='black'/>";

    // Draw arcs with center O and P
    svgFile << "<circle cx='" << O.x << "' cy='" << O.y << "' r='" << radius << "' fill='none' stroke='blue'/>";
    svgFile << "<circle cx='" << P.x << "' cy='" << P.y << "' r='" << radius << "' fill='none' stroke='green'/>";

    // Draw points O, A, B, and P
    // ...

    // Draw lines CP and DP
    // ...

    // Draw line l through G and H (assuming that points G and H have been calculated)
    // ...

    // End the SVG file
    svgFile << "</svg>";
    svgFile.close();

    std::cout << "The construction diagram has been generated and saved to 'construction.svg'." << std::endl;

    return 0;
}
stdout
The construction diagram has been generated and saved to 'construction.svg'.