Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Solve(-) not working, gives out empty vector #25

Open
Icaka00 opened this issue Feb 16, 2023 · 1 comment
Open

.Solve(-) not working, gives out empty vector #25

Icaka00 opened this issue Feb 16, 2023 · 1 comment

Comments

@Icaka00
Copy link

Icaka00 commented Feb 16, 2023

Hi, great work on the splines code. I just have a small issue i stumbled upon using it in my project. I'm trying to recreate this splines into my code. Thanks in advance! Here is the issue, the splines and my code:
image
image

 int WorldGen(float Cont, float Eros, float PV ) {
			int worldHeight = 0;
			//Peakes & Valleys
			std::vector<double> x1, y1;
			x1.push_back(0.05f);
			y1.push_back(0.f);

			x1.push_back(0.1f);
			y1.push_back(0.1f);

			x1.push_back(0.325f);
			y1.push_back(0.2f);

			x1.push_back(0.5f);
			y1.push_back(0.21f);

			x1.push_back(0.65f);
			y1.push_back(0.55f);

			x1.push_back(0.9f);
			y1.push_back(0.61f);

			x1.push_back(1.f);
			y1.push_back(0.65f);
			tk::spline PVSpl;
			PVSpl.set_points(x1, y1);

			//Erosion
			std::vector<double> x2, y2;
			x2.push_back(0);
			y2.push_back(1);

			x2.push_back(0.15f);
			y2.push_back(0.55f);

			x2.push_back(0.3f);
			y2.push_back(0.41f);

			x2.push_back(0.32f);
			y2.push_back(0.45f);

			x2.push_back(0.45f);
			y2.push_back(PVSpl.solve(PV)[0]);

			x2.push_back(0.6f);
			y2.push_back(0.11f);

			x2.push_back(0.7f);
			y2.push_back(0.11f);

			x2.push_back(0.72f);
			y2.push_back(0.28f);

			x2.push_back(0.78f);
			y2.push_back(0.28f);

			x2.push_back(0.79f);
			y2.push_back(0.11f);

			x2.push_back(0.85f);
			y2.push_back(0.05f);

			x2.push_back(1.f);
			y2.push_back(0.05f);
			tk::spline ErosSpl;
			ErosSpl.set_points(x2, y2);

			//Continetalness
			std::vector<double> x3, y3;
			x3.push_back(0);
			y3.push_back(1);

			x3.push_back(0.09f);
			y3.push_back(0.025f);
			
			x3.push_back(0.345f);
			y3.push_back(0.025f);
			
			x3.push_back(0.385f);
			y3.push_back(0.435f);

			x3.push_back(0.515f);
			y3.push_back(0.435f);

			x3.push_back(0.525f);
			y3.push_back(0.9f);

			x3.push_back(0.55f);
			y3.push_back(0.915f);

			x3.push_back(0.72f);
			y3.push_back(ErosSpl.solve(Eros)[0]);

			x3.push_back(1.f);
			y3.push_back(0.98f);

			tk::spline ContSpl;
			ContSpl.set_points(x3, y3);
			
			worldHeight = ContSpl.solve(Cont)[0] * 100;

			return worldHeight;
		}
@Icaka00
Copy link
Author

Icaka00 commented Feb 19, 2023

code update:

int WorldGen(float Cont, float Eros, float PV ) {
			int worldHeight = 0;
			//Peakes & Valleys
			std::vector<double> x1 = { 0.05f, 0.1f, 0.325f, 0.5f,  0.65f, 0.9f,  1.f };
			std::vector<double> y1 = { 0.f,   0.1f, 0.2f,   0.21f, 0.55f, 0.61f, 0.65f };
			tk::spline PVSpl;
			PVSpl.set_points(x1, y1, tk::spline::cspline);
			std::vector<double> PVSol = PVSpl.solve(PV);

			//Erosion
			std::vector<double> x2 = { 0.f, 0.15f, 0.3f,  0.32f, 0.45f,    0.6f,  0.7f,  0.72f, 0.78f, 0.79f, 0.85f, 1.f };
			std::vector<double> y2 = { 1.f, 0.55f, 0.41f, 0.45f, PVSol[0], 0.11f, 0.11f, 0.28f, 0.28f, 0.11f, 0.05f, 0.05f};
			tk::spline ErosSpl;
			ErosSpl.set_points(x2, y2, tk::spline::cspline);
			std::vector<double> ErosSol = ErosSpl.solve(Eros);

			//Continetalness
			std::vector<double> x3 = { 0.f, 0.09f,  0.345f,  0.385f, 0.515f, 0.525f,  0.55f,  0.72f,      1.f};
			std::vector<double> y3 = { 1.f, 0.025f, 0.025f,  0.435f, 0.435f, 0.9f,    0.915f, ErosSol[0], 0.98f};
			tk::spline ContSpl;
			ContSpl.set_points(x3, y3, tk::spline::cspline);
			
			worldHeight = ContSpl.solve(Cont)[0] * 100;

			return worldHeight;
		}

@Icaka00 Icaka00 changed the title Please Help, strange issue .Solve(-) not working, gives out empty vector Feb 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant