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

cubic spline tangent #18

Open
baronzzl opened this issue Aug 30, 2021 · 2 comments
Open

cubic spline tangent #18

baronzzl opened this issue Aug 30, 2021 · 2 comments

Comments

@baronzzl
Copy link

Hello I try to use get cubic spline tangent, then compute normal dir of tangent to offset spline. but it strange as showing follow image:
图片
What may this problem?

@ejmahler
Copy link
Owner

ejmahler commented Sep 8, 2021

It would help to have some more information. What is the green line? What is the black line? And what are the red lines?

Could you share the code you used to make this picture?

@baronzzl
Copy link
Author

thanks for your reply. green line create from the black line offseting alone normal dir. The red line is normal dir. normal dir caculate from control point's tangent. Cubic b spline is right, show as below, but natural spline is error, show as above.
图片
code as below:

void RadiusCompensate2D(const Point2Ds &_closedSpline, double offset, bool bInner,
	Point2Ds & offsetSpline, Point2Ds *offsetDirs)
{
	TIMED_SCOPE(t, "半径补偿耗时");
	Point2Ds closedSpline = _closedSpline;
	if (closedSpline.size() < 5) return;
	auto spline = LoopingNaturalSpline<Vector2d>(closedSpline, 0.5);
	int count = closedSpline.size();
	Point2Ds rePts(count);
	Point2Ds reDirs(count);
	Point2Ds _offsetPts(count);
	double costhr = cos(M_PI / 6);
	for (int i = 0; i < count; ++i) {
		const Vector2d &tanDir = spline.getTangent(i).tangent.normalized();
		reDirs[i](0) = tanDir(1);
		reDirs[i](1) = -tanDir(0);
		auto _pt = closedSpline[i];
		rePts[i] = _pt + nor2d * offset;
		bool bIn = geo::isInBolygon(rePts[i], closedSpline);
		if (bIn != bInner) {
			reDirs[i]= -reDirs[i];
			rePts[i] = _pt + reDirs[i]* offset;;
		}
	}
	offsetSpline.swap(rePts);
	if(offsetDirs) offsetDirs->swap(reDirs);
}

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

2 participants