Message Boards Message Boards

0
|
5880 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Find the Maximized area of a Triangle given coordinates (and more)?

Posted 8 years ago

Simply put, I am trying to find the MAXIMIZED area(s) of a triangle given a bunch of coordinates. I will explain each part of my code and explain more in depth to this task..This task is to take 3 coordinate pairs and produce the area. This application is used in determining where to place water wells, such that the entire plot of land is used most efficiently for crops. At the very end I'll show you where I am having trouble in completing this task.

Clear[d, a, b, c, d, semi, area, wellList, tripleList, doubleList, possDoubleList, possTripleList, orderedDoubleList, orderedTripleList, bestDoubleWells, bestTripleWells, bestWells];

"wellList" is my possible coordinates of location (somewhere in quadrant 1, for now they can be any coordinates)

 wellList = {{0, 0}, {100, 300}, {175, 225}, {200, 350}, {400, 500}};

Here is my "Area" function nested with a distance function and perimeter function, I am using Herons Formula

 d[a_, b_] := Sqrt[(a[[1]] - b[[1]])^2 + (a[[2]] - b[[2]])^2];

 semi[a_, b_, c_] := (d[a, b] + d[a, c] + d[b, c])/2;

 area[a_, b_, c_] := Sqrt[semi[a, b, c]*(semi[a, b, c] - d[a, b])*(semi[a,b,c] - d[a, c])*(semi[a, b, c] - d[b, c])];

Here is my list of tuples (all the possible ways to arrange the coordinates in sets of 3, used to then find the area)

tripleList = Subsets[wellList, {3}]

Now I am going to iterate over my "tripleList" to produce the areas that correspond to each list in "tripleList"

possTripleList = Table[{N[area[tripleList[[i]][[1]], tripleList[[i]][[2]], tripleList[[i]][[3]]]], tripleList[[i]]}, {i, Length[tripleList]}]

Here I order the "possTripleList" by the area

 orderedTripleList = Sort[possTripleList, #1[[1]] > #2[[1]] &]

Now here is a nice grid format of the area along with the 3 coordinate pairs

 bestTripleWells = TableForm[Grid[Table[orderedTripleList[[i]], {i, Length[wellList]}], Frame -> All]]

Now here is where I am having some trouble: I need to create a function such as "topWells" using my "wellList" from above, and produce a table of the top 3 wells that have the largest area, along with the 3 coordinate pairs that correspond to it. I have a minimum area of 20,000 that must be met. Meaning if I were to edit my "wellList" so that none of the areas are greater than 20,000 then I want to be able to print out a sentence like "maximum area not met" or something like that. And of course the top 3 wells need to be greater than 20,000. This is all I have thus far, not that much help, but the functions I have above are certainly correct. I was going to try to use "TakeLargest" in my function below, but TakeLargest only works on lists and I was having some complications with it

POSTED BY: Brandon Davis
4 Replies
Posted 8 years ago

Hi Brandon,

Length[niceWells] == 0 tests whether the list of nice wells is empty, "==" is the shorthand symbol for "Equal". The RegionQ test in the function getArea takes care of the case that three points accidently are located on a single line and in that case do not qualify for a proper 2 dimensional region.

POSTED BY: Michael Helmle
Posted 8 years ago
In[22]:= wellList = {{0, 0}, {100, 300}, {175, 225}, {200, 350}, {400,
     500}};

In[23]:= (* wellList=RandomInteger[{0,500},{90,2}];*)(* for \
performance test *)

In[24]:= triangles = Subsets[wellList, {3}];

In[25]:= Length[triangles]


In[26]:= getArea[threePoints_] := 
 Module[{tria = Triangle[threePoints]}, 
  If[RegionQ[tria], N[RegionMeasure[tria]], 0]]

In[27]:= Timing[
 niceWells = 
   Sort[Select[
     Map[{getArea[#], #} &, 
      N[triangles]], #[[1]] > 20000. &], #1[[1]] > #2[[1]] &];]


In[28]:= TableForm[
 Which[Length[niceWells] == 0, "no nice wells", True, 
  Take[niceWells, UpTo[3]]], TableDepth -> 2, 
 TableHeadings -> {None, {"area", "coordinates"}}]
POSTED BY: Michael Helmle
Posted 8 years ago

Very nice Michael..

Could you explain what the == 0 is doing?? I didn't even realize there was some built in functions like Triangle, RegionQ and RegionMeasure. That will nicely replace the need to define the functions I created (d,semi and area).

Thanks

POSTED BY: Brandon Davis
Posted 8 years ago

my final function I want to create (the part I'm confused on) is something like

topWells[wellList_] := If[ ...stuff...
POSTED BY: Brandon Davis
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