-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionPlotter.h
More file actions
107 lines (89 loc) · 2.27 KB
/
FunctionPlotter.h
File metadata and controls
107 lines (89 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef FUNCTION_PLOTTER_H
#define FUNCTION_PLOTTER_H
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <fstream>
// Define mathematical constants
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.71828182845904523536
#endif
using namespace std;
// Struct untuk titik 2D
struct Point2D {
double x;
double y;
};
// Struct untuk titik 3D
struct Point3D {
double x;
double y;
double z;
};
// Struct untuk range
struct Range {
double min;
double max;
double step;
};
// Struct untuk warna RGB
struct Color {
double r, g, b;
};
// Class untuk evaluasi fungsi matematika
class MathEvaluator {
private:
string expression;
// Fungsi helper untuk parsing
double parseNumber(const string& str, size_t& pos);
double parseFactor(const string& str, size_t& pos, double x, double y = 0);
double parseTerm(const string& str, size_t& pos, double x, double y = 0);
double parseExpression(const string& str, size_t& pos, double x, double y = 0);
public:
MathEvaluator(string expr);
double evaluate(double x);
double evaluate(double x, double y);
};
// Class untuk plotting 2D
class Plotter2D {
private:
vector<Point2D> points;
string functionName;
public:
Plotter2D(string funcName);
void addPoint(double x, double y);
void generateData(MathEvaluator& evaluator, Range range);
void plotToSVG(const string& filename);
void plotToConsole();
};
// Class untuk plotting 3D
class Plotter3D {
private:
vector<Point3D> points;
string functionName;
int resolution;
public:
Plotter3D(string funcName, int res = 50);
void generateSurface(MathEvaluator& evaluator, Range range);
void exportToOBJ(const string& filename);
void exportToPLY(const string& filename);
void plotToConsole();
};
// Class untuk kalkulus numerik
class NumericalCalculus {
public:
static double calculateDerivative(MathEvaluator& evaluator, double x, double h = 0.0001);
static double calculateIntegral(MathEvaluator& evaluator, double a, double b, int n = 1000);
};
// Fungsi utility
Color HSLtoRGB(double h, double s, double l);
void clearScreen();
void displayMenu();
#endif