Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.1K 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 11 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

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
POSTED BY: Udo Krause
Posted 11 years ago
Attachments:
POSTED BY: Daniel Branco
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard