Message Boards Message Boards

0
|
5946 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
Share this post:
GROUPS:

is the Filling command capable of color any region? Please help...

Posted 9 years ago

Hello colleagues!!

I have an issue with the Filling parameter in a ListPlot. I constructed an equilateral triangle of length 1, where I plot some points in barycentric coordinates, describing a curve and a line when joined (see attachment).

For the model I'm describing, I need to fill with color the upper right region, inside the triangle, defined by a segment of the red line, a segment of the blue curve, and a segment of the right side of the triangle. The region seems like a right triangle, the hipotenuse being 'curve' (actually, the red line and the right side of the triangle are perpendicular).

I tried to use the Filling option of the ListPlot command, but I'm almost convinced that it's impossible to fill the described region using Filling. I'm currently working on another approach to put color in this region, but I think this could be a nice problem for anyone of you. Hats off for the one who can solve it, and thank you in advance!!

Daniel

PD: Here's some code to replicate the exact figure:

    k1 = Table[0.01 i, {i, 0, 100}];
    yLine = k1 Sqrt[3]/2;
    xLine = (Sqrt[3] k1 + yLine)/Sqrt[3];
    k3 = Table[
      Solve[{x k1[[i]] == y 1/4, k1[[i]] + x + y == 1}, {x, y}], {i, 
       1, 101}][[All, 1]][[All, 1]][[All, 2]];
    k4 = Table[
      Solve[{x k1[[i]] == y 1/4, k1[[i]] + x + y == 1}, {x, y}], {i, 
       1, 101}][[All, 1]][[All, 2]][[All, 2]];
    yCurve = k3 Sqrt[3]/2;
    xCurve = (Sqrt[3] k4 + yCurve)/Sqrt[3];
    leftSide = Table[Sqrt[3] k1[[i]], {i, 1, 51}];
    rightSide = Table[-Sqrt[3] (k1[[i]] - 1), {i, 51, 101}];
    bottomSide = Table[0, {i, 1, 101}];
    ListPlot[{Transpose[{k1, bottomSide}], 
      Transpose[{k1[[1 ;; 51]], leftSide}], 
        Transpose[{k1[[51 ;; 101]], rightSide}], Transpose[{xLine, yLine}], 
          Transpose[{xCurve, yCurve}]}, AspectRatio -> Sqrt[3]/2, 
            PlotRange -> {{0, 1}, {0, Sqrt[3]/2}}, Joined -> True, 
              PlotStyle -> {Black, Black, Black, Red, Blue}]
Attachments:
POSTED BY: Daniel Branco
3 Replies
Posted 9 years ago

Thank you Dent de Lion and Shenghui Yang for your response... To use the Polygon command is a nice option!! Shenghui, your solution is very elegant, thank you for your help!!

Maybe the Filling command can be used to draw the region I previously described. If I use the Filling command as follows:

Filling -> {1 -> {{5}, {Yellow}}}

the figure with the yellow color is obtained, named Fig 1. On the other hand, passing the Filling command as follows:

Filling -> {3 -> {{4}, {Red, Cyan}}}

is obtained Fig 2, colored red and cyan.

If Fig 1 is imposed over Fig 2, the region previously described would be colored in cyan. However, I can't obtain the desired figure if I pass the Filling command with a combination of the two previous commands, so Filling isn't hierarchical, and don't 'overwrites' over previous colors (I used Show to obtain the proper figure from the two previous figures). Don't you think that the overlapping of colors could be a nice feature for Filling??

Attachments:
POSTED BY: Daniel Branco

The following graph should be the result you need:

fill

In this example you can benefit from the powerful symbolic nature of Wolfram Language/Mathematica. First lets find the parametric form of the curve of barycenter

Clear[curve]
curve[t_]=Simplify@{(Sqrt[3] y+Sqrt[3]/2*x)/Sqrt[3],Sqrt[3]/2*x}/.Solve[{x *(1-t)==y 1/4,(1-t)+x+y==1},{x,y}][[1]]
(* result =  {-(t/(2 (-5+4 t)))+(4 (-1+t) t)/(-5+4 t),-((Sqrt[3] t)/(2 (-5+4 t)))} *)

where $t$ ranges from $0$ to $1$. Thinking about the big blue point slides along the curve from the origin (bottom, at $t=0$) to the top (upper-most vertex of the equilateral triangle at $t=1$).

Solve for the intersection (blue point) of the obscured height and the curve:

sol=t/.FindRoot[Evaluate[Cross[Append[curve[t],0],{Cos[30 Degree],Sin[30 Degree],0}][[3]]]==0,{t,0.5}]
(* sol = 0.75 *)

The idea is that the segment between the origin and the intersection should be parallel to the hight. I use the cross product to test the parallelism.

Once you know the coordinates of the root of height, the intersection (again, the blue point) and the top vertex of the triangle along with the coordinates of the selected points along the curve we have, we put them altogether into the Polygon object:

pg = Polygon[
   Join[
         curve /@ Range[sol, 1, Abs[sol - 1]/100], 
        {{3/4, Sqrt[3]/4},curve[sol]}} ]
 ];

Use Epilog option in the ParametricPlot function to lay the graphics objects over our plot:

result

To copy all codes, please find the working notebook attached.

Attachments:
POSTED BY: Shenghui Yang

The Filling help states

Filling is an option for ListPlot, Plot, Plot3D, and related functions that specifies what filling to add under points, curves, and surfaces.

The meaning is of under is between a graphics primitive and some co-ordinate axis or plane. So Filling is not the right choice to fill some area in a graphics not related to an axis. But you know the area and can give it easly as border of a Polygon and to that polygon you give a color and that's it.

POSTED BY: Udo Krause
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract