Luxor questions

I have started learning Luxor.jl, and I find it great.

I would have two questions:

  1. Can I reverse the default coordinate system somehow?
    (i.e. x axis to the right, but y axis upwards)
  2. Can I use LaTeX expressions as text?

For the coordinate system i’d recommend to read the
(i’d guess that for inverting an axis scale(1,-1) should work)
For the LaTeX expressions i’ve not seen a Luxor usable way; the Makie plotting supports rendered LaTeX expressions by displaying real tex output, but i’ve lost track if this is reusable in other places.


Thank you for the solution, scale(1,-1) works indeed.

1 Like

I found that

works fine for simple drawings that need LaTeX (with the axes turned off, you just get a canvas). Basically Tikz/PGF with a Julia-ish interface for coordinates.


Thank you for the pointer to your LaTeX friendly package.

Dear @lobingera and @cormullion, may I have an other newbie question.

The suggested scale(1,-1) transformation works well,
providing the x axis to the right, and the y axis upwards.

However, if any text is added then it gets mirrored and becomes unreadable.
Is there a solution to this problem?

1 Like

You could write your own text function that temporarily (use gsave or @layer) resets the scale, draw the text, then returns things back to upside down.

Although I’d recommend just using the coordinate system as it is, rather than fight it… :grinning:

1 Like

I badly need the standard Cartesian coordinate system, so I need to fight.
But you are right, this code seems to work:

function mytext(str,x,y)

1 Like
function mytext(str, pos; kwargs...)
    @layer begin
        scale(1, -1)
        text(str, O; kwargs...)

@draw begin
    scale(1, -1)
    mytext("0/0", Point(0, 0))
    mytext("160/160", Point(160, 160), halign=:center)

This should work - but I wouldn’t recommend it… :slight_smile:

Thank you for all your help.
But why is it so strange that someone wants to use
the standard Cartesian coordinate system for drawing geometry?
(e.g. to use your great Luxor.jl package instead of GeoGebra)

1 Like

It’s not that it’s strange - just that I don’t know whether everything will work correctly if you work upside down. (Things like arcs will be “backwards”, won’t they?)

Working from the top left is fairly standard in computer graphics, if not maths… For example, SVG, HTML, images, arrays, many illustration applications, all start at the top left… True, there’s PostScript which is the obvious bottom-left exception…

If you’re happy to be the pioneer, I’m always here to help… :slight_smile:

1 Like

The solution is very easy. Just transform your coordinate system to the Luxor coordinate system

Let x,y be the luxor coordinate system
Let xx,yy be your coordinate system

x = xx
y = (CanvasHeight - 1) - yy

It’s that easy!

1 Like

Up to now I did not experience a problem with arc2r, carc2r, sector, pie etc.
Text was the first case, where I have run into a serious problem.

Thank you.
And what is the transformation after the origin() command?
Also it seems to me that any such transformation requires a large number
of extra function calls, in contrast to a single scale(1,-1) setting.

After the origin() command is just a translation

x = xo + (CanvasWidth/2)
y = yo + (CanvasHeight/2)

do the transformation x = xx and y = (CanvasHeight - 1) - yy

xx = xo + (CanvasWidth/2)
(CanvasHeight - 1) - yy = yo + (CanvasHeight/2)

Next do some rearrangement

xo = xx - (CanvasWidth/2)
yo = (CanvasHeight - 1) - yy - (CanvasHeight/2)

So now you can convert from your coordinate to xo,yo

And if you want to use xxo,yyo instead of your xx,yy then

xx = xxo + (CanvasWidth/2)
yy = yyo + (CanvasHeight/2)

Next do the substitution

xo = (xx) - (CanvasWidth/2)
yo = (CanvasHeight - 1) - (yy) - (CanvasHeight/2)


xo = (xxo + (CanvasWidth/2)) - (CanvasWidth/2)
yo = (CanvasHeight - 1) - (yyo + (CanvasHeight/2)) - (CanvasHeight/2)

and do some cleanup

xo = xxo
yo = -1 - yyo