Curve functions

Post Reply
User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Curve functions

Post by Dutchman »

Based on the Bezier3-function posted by Henko, I have made a 'library' of "curve functions" by which bezier-curves can be designed and plot.
In order to compact the code I have used complex numbers for the coordinates. It made the code a lot simpler and indeed more compact. An x,y coordinate is now handled as x+y*1i.
I added some gain to the handles so that the top of the curve can reach the length of the handles. Otherwise the 'handling'-area should be larger then the drawing area.
Touch-info is handled such that the point which is moved can be moved close to or on other points.

The file "curve functions" contains the functions with info on usage
The file "Curve functions demo" is a test and demo-program.
The file "- Read Me" gives some basic information.

The files are available on Dropbox at:
https://www.dropbox.com/sh/8gk14ixlg5x4 ... rBWAa?dl=0.

The following screenshot is a reduced version from iPad
reduced screenshot.PNG
reduced screenshot.PNG (66.84 KiB) Viewed 1249 times
The following is a screenshot from ipad in which the display is tested on iPhone-size.
iPhone size on iPad.PNG
iPhone size on iPad.PNG (34.05 KiB) Viewed 1249 times
Last edited by Dutchman on Sun Sep 10, 2017 6:00 pm, edited 1 time in total.

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Curve functions

Post by Dutchman »

I forgot to simplify the equations in the Bezier-function.
It is corrected now in the Dropbox-files as follows:

Code: Select all

DEF Bezier3G(p(),xx(),yy())
'gain' and 'points' should be preset
'---- apply gain to handlesize
DIM q(2)
q(1)=p(1)+gain*(p(2)-p(1))
q(2)=p(4)+gain*(p(3)-p(4))
'---- draw curve
DRAW TO REAL(p(1)),IMAG(p(1))
t=0 ! delta=1/(points-1)
FOR i=1 TO points
  tm=1-t ! tt=3*t*tm
  a=tm^3 ! b=tm*tt ! c=t*tt ! d=t^3
  xy=a*p(1)+b*q(1)+c*q(2)+d*p(4)
  x=REAL(xy) ! y=IMAG(xy)
  xx(i)=x ! yy(i)=y
  DRAW LINE TO x,y 'in current color
  t+=delta
NEXT i
END DEF

Post Reply