lilypond-user
[Top][All Lists]

## How to get X/Y-extent of a bezier-curve?

 From: Thomas Morley Subject: How to get X/Y-extent of a bezier-curve? Date: Tue, 6 Oct 2015 13:37:11 +0200

Hi all,

I'm going to write a generic bow-stencil.
Below you'll find a boiled down example.

The main problem: how to determine the correct extents.
Looks like I need to calculate the actual X/Y-extents of the resulting
bezier-curve.
Though, obviously my maths-skills are not sufficient.

Any hints?

\version "2.18.2"

%% overlay' is in the source for 2.19.28
%% for lower versions use:
#(define-markup-command (overlay layout props args) (markup-list?)
(apply ly:stencil-add (interpret-markup-list layout props args)))

#(define (make-simple-bezier-stencil coords)
(let* ((command-list (moveto
,(car (list-ref coords 3))
,(cdr (list-ref coords 3))
curveto
,(car (list-ref coords 0))
,(cdr (list-ref coords 0))
,(car (list-ref coords 1))
,(cdr (list-ref coords 1))
,(car (list-ref coords 2))
,(cdr (list-ref coords 2))
)))
(ly:make-stencil
(path 0.1 (,@' ,command-list) 'round 'round #f)
;;;; TODO
;;;; How to get correct extents?
;; xext:
(cons
(car (list-ref coords 2))
(car (list-ref coords 3)))
;;yext:
(cons
(cdr (list-ref coords 2))
(cdr (list-ref coords 1)))
)))

%%%%%%%%%%%%%%%%%
%% EXAMPLE
%%%%%%%%%%%%%%%%%

#(define pts-list
'((12 . 8)
(5 . 8)
(2 . 2)
(15 . 2)))

#(define (rotated-pts-list degree)
(map
(lambda (c)
;;;; TODO
;; coord-rotate rotates around '(0 . 0)
;; make it generic
pts-list))

\markup
\column {
\vspace #3
\fill-line {
\overlay {
\circle \null %% representing point '(0 . 0)
\box \with-color #red {
\stencil
#(make-simple-bezier-stencil pts-list)
\stencil
#(make-simple-bezier-stencil (rotated-pts-list 90))
\stencil
#(make-simple-bezier-stencil (rotated-pts-list 60))
}
}
}
}

Cheers,
Harm