2

I have to implement a spline drawing in qt based on data from a dxf file. Data about the spline always contains only coordinates of control points.

A QPainterPath function cubicTo() uses a current point, an end point (this one belongs to a spline) and 2 control points. When I want to build a spline through 5 or more control points using several cubic Bezier splines, I don't know coordinates of fit point (that belongs to the spline) between them to use cubicTo(). Also I'm not sure that an image of the spline will be correct if I'll just combine several cubic splines after calculating a missing fit point on my original spline.

What algorithm can I use to build a spline through more than 4 control points in qt, with information only about control points, not fit points?

For example, after parsing my dxf I get coordinates of control points marked as red: enter image description here At the first, I was expecting these control points are control points of Bezier curve. I have tried even to calculate them, but amount of control points for Bezier curve is more than 6 in this case. I was using an algorithm from this question. So I understand how to calculate control points, knowing fit points, but how to do it in a reverse with kind of points I get from dxf. If you'll try to use an calculation algorithm from a question for the spline like on an image, you'll get more than 6 control points, so it's some other way to characterize it.

Here is an image to show the difference between data got from this algorithm and data I have: enter image description here What math do I need to solve this and how to get mathematical description of these points? Thanks for any help.

Jr_vv
  • 41
  • 4
  • @jr_w As already described below, there are several possibilities. One would be to recognize each control point via mouseMoveEvent and activating mouse tracking when entering the form. Have you ever looked at the example in qt creator `Affine Transformations`? maybe this will help you a bit. In that case, they wouldn't have to do a lot of calculations. – BanAnn Feb 22 '23 at 16:32
  • What do you call "fit points" ? –  Feb 22 '23 at 16:50
  • There are two ways to draw a spline in almost any CAD: with control points (red on my both pictures, I have this type stored in my data) and with fit points, that belong to a spline (they have numeration on the second picture). – Jr_vv Feb 22 '23 at 21:56

1 Answers1

1

There are many different flavours of cubic interpolation algorithms (it seems this is your goal: to interpolate between the control points from your file) that you could use, and many of them are implemented in alglib. It is open-source and available for many programming languages, including C++.

See this link for a list of alglib's supported functions and short description of it.

This one is LGPL licensed but you get what you pay for, so to speak, as in no support and no guarantees that this will actually work. (Also it's written in a very academic way that doesnt deserve the "C++" label, and it doesnt do any bounds checking whatsoever)

If you don't like or can't use commercial libraries, and want to do it "by hand", wikipedia (check the references) got you covered.

markus-nm
  • 805
  • 5
  • 8