# region plot in a 2-simplex

I want to plot a 2-dimensional region with constraint $x+y\le N$, i.e., I want to plot a sub-region inside a 2-simplex.

As an example:

Module[{n = 300, p = 0.5},
RegionPlot[{y > (1/2)*(n - x) && y + x <= n && y > p/(1 - p)*x},
{x, 0, n}, {y, 0, n}, FrameLabel -> {"x", "y"},
PlotStyle -> {Yellow, Opacity[0.5]}]]


What should I do to transform the region to a 2-simplex?

Edit 1 & 2 & 3

The command above will give you the following plot: which clearly satisfies the $x+y\le N$ constraint. So I want a coordinate transform that changes the shape of the yellow area into the shape of the red area in the plot below (it is from Matlab): • Is this answer helpful? – Artes Apr 17 '14 at 12:14
• It's hard to tell what you're asking. Your plot already lies in the 2-simplex $x\ge0,y\ge0,x+y\le N$. Are you looking for a plot that looks like an equilateral triangle? Please explain what you mean by "transform the region into a 2-simplex". – Rahul Apr 17 '14 at 16:39
• @Artes, not really... – wdg Apr 17 '14 at 17:14
• @RahulNarain, it's certainly related, but the OP seemed to want something rather advanced. I have a very difficult time extracting what I need from the post. – wdg Apr 17 '14 at 17:16
• guys, I have reworded the question and hope this time it is clear. – wdg Apr 18 '14 at 1:24

rp = Module[{n = 300, p = 0.5},
RegionPlot[{y > (1/2)*(n - x) && y + x <= n && y > p/(1 - p)*x},
{x, 0, n}, {y, 0, n}, FrameLabel -> {"x", "y"}, PlotPoints -> 100,
PlotStyle -> Directive[Yellow, Opacity[0.8]], ImageSize -> 300]];
toSimplex = #1 {1, 0} + #2 {1, Sqrt}/2 &;
Panel@Row[{rp, MapAt[toSimplex @@ # &, rp, {{1, 1, ;;}}]}] rp2 = Module[{n = 300, p = 0.5},  RegionPlot[{y > (1/2)*(n - x) && y + x <= n &&
y > p/(1 - p)*x,  x + y < n}, {x, 0, n}, {y, 0, n}, FrameLabel -> {"x", "y"},
PlotStyle -> {Directive[Yellow, Opacity[0.8]], Directive[White, Opacity[0.1]]},
PlotPoints -> 100, ImageSize -> 300]];
Panel@Row[{rp2, MapAt[toSimplex @@ # &, rp2, {{1, 1, ;;}}]}]


Note: In version 9, one can use Span objects in the third argument of MapAt as first noted in this answer by Kuba. You can also use

tF = FindGeometricTransform[{{0, 0}, {1, 0}, {1, Sqrt}/2},
{{0, 0}, {1, 0}, {0, 1}}][];
MapAt[GeometricTransformation[#, tF] &, rp2, {1}] //Panel • Would you care to elaborate on the rather uncommon syntax of your MapAt call? – Sjoerd C. de Vries Apr 18 '14 at 16:38
• @Sjoerd, thanks. Updated and added a reference to Kuba's answer regarding the MapAt usage with Spans. ({{}} in the original was a copy/paste error.) – kglr Apr 18 '14 at 16:54
• It did work, even with the error... +1 anyway – Sjoerd C. de Vries Apr 18 '14 at 17:53

Module[{n=300,p=0.29,r1,r2,r3,r4,x,y}, 