[Ipe-discuss] Adding arcs with LUA in an Ipelet
Otfried Cheong
ipe at otfried.org
Mon Sep 28 15:59:58 CEST 2020
On Mon, Sep 28, 2020, at 15:10, Lluís Alemany-Puig via Ipe-discuss wrote:
> 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?
The documentation you need to look at is
http://ipe.otfried.org/manual/luageo.html#luaarc
and perhaps http://ipe.otfried.org/manual/classipe_1_1_arc.html
cx, cy is the center of the circle, r is the radius of the circle (so the matrix maps the unit circle to the circle that you want), x1 is the start point, and x2 the end point of the arc.
Your arc does not work because the points x1 x2 do not actually lie on the circle that you defined (they do not have distance r from the point (cx, cy)).
So you should try:
r = 50
center = ipe.Vector(500, 450)
x1 = ipe.Vector(550, 450)
x2 = ipe.Vector(450, 450)
arc = ipe.Arc(ipe.Matrix(r, 0, 0, r, center.x, center.y), 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)
Cheers,
Otfried
More information about the Ipe-discuss
mailing list