[Ipe-discuss] Adding arcs with LUA in an Ipelet
Lluís Alemany-Puig
lluis.alemany.puig at upc.edu
Mon Sep 28 15:10:00 CEST 2020
Hello everybody,
I'm writing an Ipelet to automatize arc drawing between pairs of points
whose coordinates are known, but I'm not sure how to do that. I've made
an ipelet before, but it is much simpler than this one.
The arcs I want to draw have well-defined right and left endpoints, and
I would like to draw them as a semicircle whose centre is the midpoint
between the left and right endpoints -- much like what one would get by
using the buttons accessible via the default keyboard shortcut [A] and
[Shift + A]: Circular arcs by centre, right and left points.
Looking at the documentation in the manual
(http://ipe.otfried.org/manual/index.html) and at other ipelets I came
up with this first approximation to add an arc:
r = 20
cx = 500
cy = 450
x1 = ipe.Vector(450,450)
x2 = ipe.Vector(450,550)
arc = ipe.Arc(ipe.Matrix(r, 0, 0, r, cx, cy), x1,x2)
arc_seg = {type="arc", x1, x2, arc = arc}
curve = {type="curve", closed = false, arc_seg}
path = ipe.Path(model.attributes, {curve})
model:creation("ACTION", path)
There are several things in this code that I do not understand, and that
I could not find in the manual. First, I would like to know the meaning
of the variables cx, cy, x1 and x2 and how to interpret the matrix
ipe.Matrix(r, 0, 0, r, cx, cy) in terms of arc creation. I wonder how I
can add the arcs I want with ipe.Arc(): how do I specify the left and
right endpoints and the centre? The code above does not add an arc with
left endpoint x1, right point x2 and centre (cx,cy). Actually, it
produces something "weird"; sorry, I can't add a picture. In case it
should, am I missing something?
These questions are, quite likely, more related to computational
geometry than to IPE itself, but it's been too long since I last did a
course on Computational Geometry (and I don't remember doing any of this).
Thank you all for your time,
Lluís.
More information about the Ipe-discuss
mailing list