[Ipe-discuss] Re: Get point coordinates in ipelets. (correction)
Günter Rote
rote at inf.fu-berlin.de
Fri Mar 26 16:28:27 CET 2010
Günter Rote wrote:
>> From: "Sebastien Loriot (GeometryFactory)" <sloriot.ml at gmail.com>
>> Subject: Re: [Ipe-discuss] CGAL points generator ipelets in Ipe 7
>>
>>> I'm writing an Ipelet in Lua that uses a set of points (markers) as
>>> input. I sort the points using their x coordinate, which I obtain
>>> using the getPosition() function of each marker object.
>
> ...
>
>>> Â¿Does anybody have any idea of why this happens?, Â¿Are not all the
>>> objects on a page referenced to the same coordinate system?
>>>
>>
>> Just a hint: ... You probably should have a look at the matrix()
>> function of ipe::Object.
>>
>
> Here is an ipelet print.lua that dumps the coordinates of a group of points
> to the terminal (written for my own convenience), assuming
> that you start ipe from the command line.
This ipelet had a bug, because I forgot another matrix to multiply with,
see below.
>
>
> --[[
> written by Günter Rote, 2010
> --]]
>
> label = "print point coordinates"
>
> about = [[
> Dump coordinates of a point set
>
> This ipelet is part of Acrobat Reader.
> ]]
>
>
> local function incorrect_input(model,s)
> model:warning("Cannot find coordinates", s)
> end
>
> local function getpoints(model,obj,which)
> if obj:type() ~= "group" then
> incorrect_input(model, which .. " selection is not a group")
> return
> end
> local marks={}
> for i,point in ipairs(obj:elements()) do
> if point:type() ~= "reference" or point:symbol():sub(1,5) ~=
> "mark/" then
> incorrect_input(model, which .. " selection is not a group of
> points")
> return
> end
The following is wrong
> marks[#marks + 1] = obj:matrix() * point:position()
here is the corrected statement
marks[#marks + 1] = obj:matrix() * point:matrix() * point:position()
> end
> return marks
> end
>
> function match(model)
> local p = model:page()
> local prim = p:primarySelection()
>
> -- get the data
> local p = getpoints(model,p[prim],"first")
> if not p then
> return
> end
>
> -- now print the data
>
> print ("[")
> for i,ps in ipairs(p) do
> print ("("..ps.x..","..ps.y .."),")
> end
> print ("]")
>
> end
>
> run = match
>
>
>
[cristo] wrote:
>> Thanks a lot for your answer, everything works perfect now. Just a question, why do
you >make the test point:symbol():sub(1,5) ~= "mark/"?, are there reference objects that
are >not a mark?
>I don't know. I copied this from some other ipelet, namely:
function parabola(model) in goodies.lua
--
G"unter Rote (Germany=49)30-838-75150 (office)
Freie Universit"at Berlin -75103 (secretary)
Institut f"ur Informatik FAX (49)30-838-75192
Takustrase 9 (49)30-84108844 (home)
D-14195 Berlin, GERMANY electronic mail: rote at inf.fu-berlin.de
More information about the Ipe-discuss
mailing list