[Interest] sin wave with QPainterPath between two points

Patrick Stinson patrickkidd at gmail.com
Thu Jul 20 10:40:23 CEST 2017


You know, I happened to have a set of points from a jagged line that was already working and then pumped that into a splining function (which calculates bezier control points) which I pirated from someone else. The jagged lines took me a long time to figure out the math for, and I have no idea how the splining function works!

Note one jagged line and one splined line with same points in attached screenshot:

So I guess I’m all good here…

Thanks!




> On Jul 20, 2017, at 1:36 AM, Elvis Stansvik <elvstone at gmail.com> wrote:
> 
> 2017-07-20 10:30 GMT+02:00 Patrick Stinson <patrickkidd at gmail.com>:
>> Also it should be between two arbitrary points, so the sine wave may go from
>> top-right to bottom left, for example.
> 
> Right, but that's just a transformation of the bezier control points
> once you have them.
> 
> Elvis
> 
>> 
>> On Jul 20, 2017, at 1:28 AM, Elvis Stansvik <elvstone at gmail.com> wrote:
>> 
>> 2017-07-20 10:23 GMT+02:00 Jean-Michaël Celerier
>> <jeanmichael.celerier at gmail.com>:
>> 
>> You can just compute the sine directly :
>> 
>>  for(int i = 0; i < width; i++)
>>  {
>>    int x = i;
>>    int y = height / 2 + amplitude * std::sin(2 * M_PI * freq * i / width +
>> phase);
>>    path.lineTo(x, y);
>>  }
>> 
>> 
>> I think he wanted to avoid an approximation with straight lines and
>> use cubic beziers.
>> 
>> Jean-Michaël: There seems to be many pages explaining the theory
>> behind sine approximation using Beziers if you Google.
>> 
>> Elvis
>> 
>> 
>> 
>> 
>> 
>> 
>> -------
>> Jean-Michaël Celerier
>> http://www.jcelerier.name
>> 
>> On Thu, Jul 20, 2017 at 9:47 AM, Patrick Stinson <patrickkidd at gmail.com>
>> wrote:
>> 
>> 
>> Hello! I want to figure out how to draw a sin wave between two QPointF’s
>> using QPainterPath. Calculating the cubic control points seems like the best
>> way, but I am far from mastering that theory.
>> 
>> This is a diagramming app and the goal is to get a squiggly line between
>> two objects.
>> 
>> Thanks!
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>> 
>> 
>> 
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>> 
>> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170720/a61e20a0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2017-07-20_01-38-50.jpg
Type: image/jpeg
Size: 119290 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170720/a61e20a0/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1403 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170720/a61e20a0/attachment.bin>


More information about the Interest mailing list