drawing a partial QPainterPath based on percentages?
I'm trying to draw a partial QPainterPath. I added 2 arcs connected by a line segment to a QPainterPath. What I'm trying to do is to treat the QPainterPath as a singular object, and only draw certain parts of that path based on percentages. For example, drawing between 0.2 and 0.8.
Here's what I'm aiming to do:
Does anyone know of a way I can accomplish this? It doesn't look like QPainterPath supports this, but there must be some way.
I am not sure I fully understand what you are asking so if this comment seems off then I guess I don't understand.
I believe what you have is some sort of path where the first point is considered to be zero and the last point is one. The number of points inside this path and the relative spacing is not important.
The best way to handl this is to use a spline of some sort. The spline doesn't need to smooth the data but can treat it as a polyline. You put all your points that describe this shape into a spline where the path is described as a 'u' value that typically has a range of 0 to 1 (sometimes -1 to 1).
To draw the path you would have something like this:
TSpline my_spline(point_data_describing_full_shape); TPoint point; point = my_spline.evaluate(0.); // returns the first point point = my_spline.evaluate(1.); // returns the last point point = my_spline.evaluate(0.2); // returns a point that is at 20% along the full path length. point = my_spline.evaluate(0.8); // returns a point that is at 80% along the full path length.
If using splines it may be important to space the input point data evenly. If you bunch up points in certain areas, depending on the spline math, you might find the sections are compressed relative the the number of points in the area (so 0.25 doesn't return 25% of the actual length). I always try to space out the input points evenly to minimize this problem.