Re: Circles

2022-08-11 Thread Andrew Bernard

Thanks Silvain,

As I mentioned previously on the list my background is maths and I 
understand Beziers, and I have implemented very compact code to do this. 
I appreciate your help in any case. Actaully, the main basis for the 
original post was to query what approach Lilypond takes.


I also give references to pages that give a clear derivation of the 
kappa value: 0.5522847498. I observe this is different to your value but 
I believe it to be correct based on this derivation:


http://whizkidtech.redprince.net/bezier/circle/kappa/

Wikipedia gives a similar derivation with the exact same value.

Not sure where your different number comes from.

This hardly matters as even four decimal places is probably overkill for 
Lilypond.


You can see my (poor first attempt but correct Bezier approximation_ in 
the topic 'Help with custom noteheads'.


Andrew


On 11/08/2022 11:10 pm, Silvain Dupertuis wrote:
You can draw a quasi perfect circle with a Bezier curve (cubic) with 4 
main points.

The optimal distance between main and secondary control points is
0.5517847391957151 * radius
(you do not need as many decimal places...!)






Re: Circles

2022-08-11 Thread Silvain Dupertuis

You can draw a quasi perfect circle with a Bezier curve (cubic) with 4 main 
points.
The optimal distance between main and secondary control points is
0.5517847391957151 * radius
(you do not need as many decimal places...!)

(optimal value calculated with wxMaxima and checked with Inkscape)



Le 11.08.22 à 09:05, Andrew Bernard a écrit :
As to the _real_ question (XY? ;-) ), I am needing to do custom circular noteheads, also 
with bits and bobs such as middle dots and so on and I was not able to find an arc 
operator in the markup path commands, so one needs to user curveto, which is a Bezier 
operator. Is that right?


Andrew





--
Silvain Dupertuis
Route de Lausanne 335
1293 Bellevue (Switzerland)
tél. +41-(0)22-774.20.67
portable +41-(0)79-604.87.52
web: silvain-dupertuis.org 

Re: Circles

2022-08-11 Thread David Kastrup
Werner LEMBERG  writes:

>>> Well, Metafont uses a third-order Bézier approximation to build up
>>> circles (from four quarter circles).  However, the Metafont book
>>> says that the difference to a real circle is less than 0.06%, which
>>> is thus imperceptible.
>>>
>>> The same holds for PostScript-based fonts.
>> 
>> PostScript uses second-order Béziers, so it makes little sense to
>> cite the mathematics of Metafont here.
>
> This is not correct.  PostScript-derived fonts (Type1, CFF/CFF2 in
> OpenType) *do* use third-order curves.  I think you are mixing this up
> with TrueType fonts, which indeed use second-order curves.

I was more talking about the curveto operator than fonts, but you are
right either way.  It was just Truetype that used only quadratic
Béziers.

Sort of embarrassing, since I distinctly remember putting explicit
quartercircle approximations into the curved rectangles PostScript code.
I did not find anything like that in the repository master though; it
must have been an ephemeral part of the work for better rasterized PDF
stems I did quite some time ago.

-- 
David Kastrup



Re: Circles

2022-08-11 Thread Werner LEMBERG

>> Well, Metafont uses a third-order Bézier approximation to build up
>> circles (from four quarter circles).  However, the Metafont book
>> says that the difference to a real circle is less than 0.06%, which
>> is thus imperceptible.
>>
>> The same holds for PostScript-based fonts.
> 
> PostScript uses second-order Béziers, so it makes little sense to
> cite the mathematics of Metafont here.

This is not correct.  PostScript-derived fonts (Type1, CFF/CFF2 in
OpenType) *do* use third-order curves.  I think you are mixing this up
with TrueType fonts, which indeed use second-order curves.


Werner


Re: Circles

2022-08-11 Thread David Kastrup
Werner LEMBERG  writes:

>>> There's a lot of oldish webpages with complex Bezier curve
>>> constructions for circles.
>> 
>> Those must be approximate constructions. It is not mathematically
>> possible to construct a Bézier curve which is at the same time an
>> exact circle.
>
> Well, Metafont uses a third-order Bézier approximation to build up
> circles (from four quarter circles).  However, the Metafont book says
> that the difference to a real circle is less than 0.06%, which is thus
> imperceptible.
>
> The same holds for PostScript-based fonts.

PostScript uses second-order Béziers, so it makes little sense to cite
the mathematics of Metafont here.

-- 
David Kastrup



Re: Circles

2022-08-11 Thread Andrew Bernard
There are a whole lot of custom noteheads I need that are based on 
circles with all sorts of additions like dots and things for a 
contemporary modernist work. Very special case, but they may end up 
being useful for others when I finish. I'll see if draw-circle can fit 
into the scheme of things (possible pun may be intended).


Andrew

On 11/08/2022 5:54 pm, Jean Abou Samra wrote:
Do you have so many of these note heads to draw that using 
\draw-circle is tedious? 




Re: Circles

2022-08-11 Thread Jean Abou Samra



> Le 11 août 2022 à 09:38, Andrew Bernard  a écrit :
> 
> All my other custom noteheads use curveto heavily. I was wondering if I could 
> scrimp time by using an arc command. I'm trying to avoid raw postscript as I 
> think that obviates the ability to output SVG - not that I use it but others 
> do,



Do you have so many of these note heads to draw that using \draw-circle is 
tedious?

Is it not possible to define a custom command that will draw them from some 
parameters?





Re: Circles

2022-08-11 Thread Andrew Bernard
All my other custom noteheads use curveto heavily. I was wondering if I 
could scrimp time by using an arc command. I'm trying to avoid raw 
postscript as I think that obviates the ability to output SVG - not that 
I use it but others do,


Thanks all!

Andrew


On 11/08/2022 5:16 pm, Jean Abou Samra wrote

I don’t think there is a simple way to draw an arc without using \postscript or 
approximating with Bézier curves in \path, but if all you need is a circle, see 
the \draw-circle command.




Re: Circles

2022-08-11 Thread Jean Abou Samra



> Le 11 août 2022 à 09:06, Andrew Bernard  a écrit :
> 
> As to the _real_ question (XY? ;-) ), I am needing to do custom circular 
> noteheads, also with bits and bobs such as middle dots and so on and I was 
> not able to find an arc operator in the markup path commands, so one needs to 
> user curveto, which is a Bezier operator. Is that right?


I don’t think there is a simple way to draw an arc without using \postscript or 
approximating with Bézier curves in \path, but if all you need is a circle, see 
the \draw-circle command.

Jean





Re: Circles

2022-08-11 Thread Andrew Bernard
As to the _real_ question (XY? ;-) ), I am needing to do custom circular 
noteheads, also with bits and bobs such as middle dots and so on and I 
was not able to find an arc operator in the markup path commands, so one 
needs to user curveto, which is a Bezier operator. Is that right?


Andrew





Re: Circles

2022-08-11 Thread Andrew Bernard

Thanks all,

Comments much appreciated, but I know all that, as my background is 
maths. I was just wanting to see how Lilypond does it.


And of course after I posted about oldish pages I recall of course that 
you have to do circles with Beziers in fonts, as the arc operator is not 
available. The approximation is very excellent if you use the right 
control points. If people stumble across this thread in the future, and 
want to draw circles with Beziers, these are good pages:


http://whizkidtech.redprince.net/bezier/circle/

http://whizkidtech.redprince.net/bezier/circle/kappa/


Andrew




Re: Circles

2022-08-11 Thread Silvain Dupertuis
Both Postscript and SVG have a built-in arc function capable of drawing an arc (or an 
entire circle).


Bézier 2-D curves can approximate a circle, but cannot create a mathematical exact circle 
(although an approximation using 4 points is so precise that it is practically 
indistinguishable from a circle)



Le 11.08.22 à 03:55, Andrew Bernard a écrit :

Well I suppose it is actually postscript. So I had better look at the full 
source?

On 11/08/2022 11:40 am, Andrew Bernard wrote:
Where is the code that actually draws a circle stencil? I am interested to see if it is 
done with Bezier curve techniques and to study that. I could not seem to find it in the 
scm area.


Andrew







--
Silvain Dupertuis
Route de Lausanne 335
1293 Bellevue (Switzerland)
tél. +41-(0)22-774.20.67
portable +41-(0)79-604.87.52
web: silvain-dupertuis.org 

Re: Circles

2022-08-11 Thread Werner LEMBERG
>> There's a lot of oldish webpages with complex Bezier curve
>> constructions for circles.
> 
> Those must be approximate constructions. It is not mathematically
> possible to construct a Bézier curve which is at the same time an
> exact circle.

Well, Metafont uses a third-order Bézier approximation to build up
circles (from four quarter circles).  However, the Metafont book says
that the difference to a real circle is less than 0.06%, which is thus
imperceptible.

The same holds for PostScript-based fonts.


Werner


Re: Circles

2022-08-11 Thread Jean Abou Samra




Le 11/08/2022 à 06:14, Andrew Bernard a écrit :

Ah yes it is in the postscript area of the source code.

/draw_circle % filled? radius thickness draw_circle
{
    setlinewidth    % f? r
    currentpoint    % f? r x0 y0
    3 2 roll    % f? x0 y0 r
    dup 0 rmoveto
    0 360 arc closepath
    stroke_and_fill?
} bind def

Simple use of 360 degree arc. Answers what I wanted to know.



OK. Out of curiosity, what was the context?

There's a lot of oldish webpages with complex Bezier curve 
constructions for circles.


Those must be approximate constructions. It is not mathematically 
possible to construct a Bézier curve which is at the same time an exact 
circle.



Perhaps a version earlier than Postscript 3 did not have the arc 
operator. Otherwise I don't know why you would bother.


I see arc in the PostScript level 2 manual:

https://www.os2site.com/sw/dev/openwatcom/docs/postscript_level_2_reference_manual.pdf

and given it's such a fundamental command, I am pretty sure it has been 
there from the beginning.


Best,
Jean




Re: Circles

2022-08-10 Thread Andrew Bernard

Ah yes it is in the postscript area of the source code.

/draw_circle % filled? radius thickness draw_circle
{
    setlinewidth    % f? r
    currentpoint    % f? r x0 y0
    3 2 roll    % f? x0 y0 r
    dup 0 rmoveto
    0 360 arc closepath
    stroke_and_fill?
} bind def

Simple use of 360 degree arc. Answers what I wanted to know. There's a 
lot of oldish webpages with complex Bezier curve constructions for 
circles.Perhaps a version earlier than Postscript 3 did not have the arc 
operator. Otherwise I don't know why you would bother.


Sorry for the noise.


On 11/08/2022 11:40 am, Andrew Bernard wrote:
Where is the code that actually draws a circle stencil? I am 
interested to see if it is done with Bezier curve techniques and to 
study that. I could not seem to find it in the scm area.


Andrew







Re: Circles

2022-08-10 Thread Andrew Bernard
Well I suppose it is actually postscript. So I had better look at the 
full source?


On 11/08/2022 11:40 am, Andrew Bernard wrote:
Where is the code that actually draws a circle stencil? I am 
interested to see if it is done with Bezier curve techniques and to 
study that. I could not seem to find it in the scm area.


Andrew







Re: Circles round fingerings

2020-07-02 Thread Pierre Perol-Schneider
You're welcome Paul.
Cheers,
Pierre
PS. Be sure to respond to the list.

Le jeu. 2 juil. 2020 à 14:31, Paul McKay  a écrit :

> Thanks for this Pierre. I can now do just what I'd hoped. I'm still
> struggling to write the appropriate markup function, but I'll keep going!
> Paul
>
> On Wed, 24 Jun 2020 at 15:23, Pierre Perol-Schneider <
> pierre.schneider.pa...@gmail.com> wrote:
>
>> Hi Paul,
>> How about:
>>
>> \version "2.20.0"
>>
>> customFingering = {
>>   \override Fingering.font-name = "Arial Black"
>>   \override Fingering.font-size = #-1
>>   \override Fingering.color = #(x11-color "DarkRed")
>> }
>>
>> cust =
>>   -\tweak font-name #"Arial Black"
>>   -\tweak font-size #-2
>>   -\tweak color #(x11-color "DarkRed") \etc
>>
>> tune = \relative {
>> %\customFingering
>> c'4 d-2  e\3 % <= optional
>> \cust-\markup\circle "3"
>> g-5 %-\markup {\center-align \draw-circle #1 #.5 ##f }
>> }
>> \score {
>> <<
>> \time 4/4
>> \new Staff \tune
>> >>
>> \layout {
>>   \context {
>> \Score
>> \override Fingering.font-name = "Arial Black"
>> \override Fingering.font-size = #-1
>> \override Fingering.color = #(x11-color "DarkRed")
>> %Optional:
>> \override StringNumber.font-name = "Arial Black"
>> \override StringNumber.font-size = #-2
>> \override StringNumber.color = #(x11-color "DarkRed")
>>   }
>> }
>> }
>>
>> Of course, you could also define a markup function to get a shortcut for
>> the circled fingering...
>> Cheers,
>> Pierre
>>
>>
>> Le mer. 24 juin 2020 à 15:19, Paul McKay  a écrit :
>>
>>> Hi
>>> I'd like to put a circle round occasional fingering marks. I have tried
>>> *\circle*, but seem to have no control of the resulting thickness nor
>>> of the font features. I can find no way to customize the fingering font
>>> within the *\circle: *I always get some error message or other.
>>>
>>> I tried \draw-circle, but that's a kludge and I can't make it overlap.
>>>
>>> What I'd really like is to set up the fingering font attributes at the
>>> Score level so that I don't have to reset them every time I use fingering
>>> in a music expression. Perhaps that would encourage *\circle* to use
>>> them. In the following example, I'd really like to see a fingering on the e
>>> which has a bold red circle around it and properly centred. It would be
>>> good if it could handle tweaks to the Y-offset too because the circle might
>>> collide with other things.
>>>
>>> Thanks
>>> Paul McKay
>>>
>>> Example:
>>> \version "2.20.0"
>>>
>>> customFingering = {
>>> \override Fingering.font-name = "Arial Black"
>>> \override Fingering.font-size = #-1
>>> \override Fingering.color = #(x11-color "DarkRed")
>>> }
>>> tune = \relative {
>>> \customFingering
>>> c'4 d-2  e -\markup {   { \circle \finger  "3" } }
>>> g-5-\tweak Y-offset 5 -\markup {\center-align \draw-circle #1 #.5
>>> ##f }
>>> }
>>> \score {
>>> <<
>>> \time 4/4
>>> \new Staff \tune
>>> >>
>>> \layout {}
>>> }
>>>
>>


Re: Circles round fingerings

2020-06-24 Thread Pierre Perol-Schneider
Hi Paul,
How about:

\version "2.20.0"

customFingering = {
  \override Fingering.font-name = "Arial Black"
  \override Fingering.font-size = #-1
  \override Fingering.color = #(x11-color "DarkRed")
}

cust =
  -\tweak font-name #"Arial Black"
  -\tweak font-size #-2
  -\tweak color #(x11-color "DarkRed") \etc

tune = \relative {
%\customFingering
c'4 d-2  e\3 % <= optional
\cust-\markup\circle "3"
g-5 %-\markup {\center-align \draw-circle #1 #.5 ##f }
}
\score {
<<
\time 4/4
\new Staff \tune
>>
\layout {
  \context {
\Score
\override Fingering.font-name = "Arial Black"
\override Fingering.font-size = #-1
\override Fingering.color = #(x11-color "DarkRed")
%Optional:
\override StringNumber.font-name = "Arial Black"
\override StringNumber.font-size = #-2
\override StringNumber.color = #(x11-color "DarkRed")
  }
}
}

Of course, you could also define a markup function to get a shortcut for
the circled fingering...
Cheers,
Pierre


Le mer. 24 juin 2020 à 15:19, Paul McKay  a écrit :

> Hi
> I'd like to put a circle round occasional fingering marks. I have tried
> *\circle*, but seem to have no control of the resulting thickness nor of
> the font features. I can find no way to customize the fingering font within
> the *\circle: *I always get some error message or other.
>
> I tried \draw-circle, but that's a kludge and I can't make it overlap.
>
> What I'd really like is to set up the fingering font attributes at the
> Score level so that I don't have to reset them every time I use fingering
> in a music expression. Perhaps that would encourage *\circle* to use
> them. In the following example, I'd really like to see a fingering on the e
> which has a bold red circle around it and properly centred. It would be
> good if it could handle tweaks to the Y-offset too because the circle might
> collide with other things.
>
> Thanks
> Paul McKay
>
> Example:
> \version "2.20.0"
>
> customFingering = {
> \override Fingering.font-name = "Arial Black"
> \override Fingering.font-size = #-1
> \override Fingering.color = #(x11-color "DarkRed")
> }
> tune = \relative {
> \customFingering
> c'4 d-2  e -\markup {   { \circle \finger  "3" } }
> g-5-\tweak Y-offset 5 -\markup {\center-align \draw-circle #1 #.5 ##f }
> }
> \score {
> <<
> \time 4/4
> \new Staff \tune
> >>
> \layout {}
> }
>