I have started learning `Luxor.jl`

, and I find it great.

I would have two questions:

- Can I reverse the default coordinate system somehow?

(*i.e.*x axis to the right, but y axis upwards) - Can I use LaTeX expressions as text?

I have started learning `Luxor.jl`

, and I find it great.

I would have two questions:

- Can I reverse the default coordinate system somehow?

(*i.e.*x axis to the right, but y axis upwards) - Can I use LaTeX expressions as text?

2 Likes

For the coordinate system iâ€™d recommend to read the http://juliagraphics.github.io/Luxor.jl/stable/transforms/

(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.

4 Likes

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.

2 Likes

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â€¦

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)
gsave()
scale(1,-1)
text(str,x,-y)
grestore()
end
```

1 Like

```
function mytext(str, pos; kwargs...)
@layer begin
translate(pos)
scale(1, -1)
text(str, O; kwargs...)
end
end
@draw begin
fontsize(30)
scale(1, -1)
rulers()
mytext("0/0", Point(0, 0))
mytext("160/160", Point(160, 160), halign=:center)
end
```

This should work - but I wouldnâ€™t recommend itâ€¦

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â€¦

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)

to

xo = (xxo + (CanvasWidth/2)) - (CanvasWidth/2)

yo = (CanvasHeight - 1) - (yyo + (CanvasHeight/2)) - (CanvasHeight/2)

and do some cleanup

xo = xxo

yo = -1 - yyo