1
$\begingroup$

I would like to define some simple geometric primitives (e.g. points and lines) and see what happens when I transform them by a non-linear transformation (in my case $(x,y)\mapsto (\sqrt x,\sqrt y)$). The result should be an image showing $\{(\sqrt x, \sqrt y)|(x,y)\in X\}$, where $X$ is some set I defined before, like union of points and lines.

===

I tried playing with TransformedRegion. I can apply it to a single line, but for example {Line[p1,p2],Line[p2,p3]} is not a correctly specified region. Also, putting TransformedRegion[Line[p1,p2],F] (for some defined function F) to Graphics does not work, since "TransformedRegion is not a Graphics primitive or directive".

$\endgroup$
4
$\begingroup$

There are a couple things to discuss here.

TransformedRegion output

The output of TransformedRegion is a region object. In general, to view a region object, you need to use Region or DiscretizeRegion on it. The exception is if TransformedRegion returns a primitive region, e.g., Point, Line, etc., in which case you can just use Graphics to view it. For example, here is a trivial transformation where TransformedRegion is able to return a primitive region:

reg = Line[{{1, 0}, {5, 1}}];
new = TransformedRegion[reg, RotationTransform[Pi/4]]

Line[{{{1/Sqrt[2], 1/Sqrt[2]}, {2 Sqrt[2], 3 Sqrt[2]}}}]

You can use Graphics to view this primitive:

Graphics[new]

enter image description here

Here is your square root transformation, where TransformedRegion is unable to create a primitive region:

new = TransformedRegion[reg, Sqrt]

TransformedRegion[Line[{{1, 0}, {5, 1}}], Sqrt]

For this kind of output, you need to use Region or DiscretizeRegion:

Region[new]

enter image description here

TransformedRegion input

The input to TransformedRegion should be a region object. This is why Line[p1, p2] works and {Line[p1, p2], Line[p2, p3]} does not work. If you want to transform the union of the two lines, use RegionUnion:

reg = RegionUnion[
    Line[{{1, 0}, {3, 1}}],
    Line[{{0, 2}, {3, 0}}]
];
new = TransformedRegion[reg, Sqrt];
Region[new, PlotRange -> {{0,Sqrt[3]},{0,Sqrt[2]}}]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you! I can put together what I need with these. Another question is, however, whether using Region is actually the best way to go. Are there also some other nice possibilities? $\endgroup$ – OnDragi Sep 12 at 12:34
  • $\begingroup$ Also, is there a way to increase the precision? I tried the following code: a = {.1, .2}; b = {.15, .1}; c = {.3, .6}; d = {.4, .5}; Region[TransformedRegion[ RegionUnion[Line[{a, b}], Line[{a, c}], Line[{b, c}], Line[{c, d}], Line[{b, d}]], {Indexed[#, 1]^2, Indexed[#, 2]^2} &]]. The result does not show the transformed edge (a,b). I can see this edge if I remove, e.g., Line[{b,d}] from the union. $\endgroup$ – OnDragi Sep 12 at 12:54
  • $\begingroup$ @OnDragi I think the issue is that Region is having difficulty figuring out the region bounds. If you include something like PlotRange -> {{0, .2}, {0, .4}} to your Region call, it should show the missing line. $\endgroup$ – Carl Woll Sep 12 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.