How can I calculate the analysis grid area?

How would I go about calculating the area of the analysis grid that is above a given threshold value. I know I can find the percentage of all points above it, but I need the actual floor-area and preferably very accurately.

This Ecotect script demonstrates how to iterate over the current analysis grid in your model and calculate the actual surface area that is above a given threshold, in this case the current minimum scale value. Whilst Ecotect can already show the percentage of grid points above a threshold, this script includes the fractional areas of cells that are partially above and partially below.

A major part of this script is the interpolation of the effective surface area of those grid cells in which some of the node values are above the threshold and some below. Whilst it is possible to manually adjust the spacing of grid cells along each axis, such that individual grid cells can be of significantly different sizes, the analysis grid is always rectilinear so that the calculation of intersection areas is relatively straightforward. Figure 1 shows some examples of the equations required to determine the area of grid cells with different threshold intersections.

Figure 1 - Some examples of the various contour intersections with a rectangular grid cell.

Figure 1 - Some examples of the various contour intersections with a rectangular grid cell.

The right-most example shown in Figure 1 above shows that, in some instances, it is possible for the same threshold contour to pass through the same grid square twice. This effect is relatively easy to calculate, however it can occur on any combination of the four opposing corners, which makes it laborious to constantly test for.

Having always been a fan of the ''simpler is better'' principle, the code required to properly detect and handle all of these possible variations over the four edges of each cell was starting to balloon out pretty badly. Looking for a much simpler option that still demonstrated the same principles, I considered testing each cell as two separate triangles.

With a triangle, a particular contour line can only pass through it once. If it does, then there will always be either one corner above the threhold and two below, or two above and one below. This greatly simplifies the number of options that have to be checked for and handled.

Figure 2 - The four variations of contour intersections with a triangular facet.

Figure 2 - The four variations of contour intersections with a triangular facet.

Also, because we are only interested in the 2D area of the grid in order to derive the floor area (in this particular script), we only need to deal with the X and Y components of each grid cell's corner position. This makes the calculation of the effective surface area of a triangle pretty simple. Based on the triangle area equation given at the Math Open Reference website, we can start with a very simple function in our script.

-- Return the area of a triangle comprising 3x2D points.
-- Dividing by 2x1000  converts millimetre positions into metres squared areas.
function areaOfTriangle(Ax, Ay, Bx, By, Cx, Cy)
    return (abs((Ax * (By - Cy)) + (Bx * (Cy - Ay)) + (Cx * (Ay - By))) / 2000.0)
end

We also need a couple of extra helper functions; the main one being for linearly interpolating the contour intersection value between two corners that cross the threshold.

-- A simple boolean test.
function isAbove(value, threshold)
  if value >= threshold then
    return 1
  end
  return 0
end

-- Performs a linear interpolation between 
-- (v1 -> v2) given the ratio of u to (u1 -> u2).
function Interpolate(u, u1, u2, v1, v2)

  -- If division by zero, return average of v1 and v2.
  if u2 ~= u1 then 
    return((((u - u1) / (u2 - u1)) * (v2 - v1)) + v1)
  else 
    return((v1 + v2) / 2.0) 
  end

end

Once we have these, we can create a function to test each triangle within a given grid cell and return its area. In Ecotect it is possible to hide parts of the analysis grid, so the first step is to check that all three triangle points are visible. Then. if all points are above the threshold, its entire area is returned. If all points are below, it returns zero area. We then need to check for either one or two points below the threshold.

-- ================================================
-- CELL ANALYSIS FUNCTIONS.
--  rows(Y)
--  di---C---ci             4---C---3
--   |     / |              |     / |
--   D   /   B              D   /   B
--   | /     |              | /     |
--  ai---A---bi cols(X)     1---A---2
-- ================================================

function getAreaOfTriangleAboveThreshold(threshold, index, cell)

  -- Check which trianglular facet to use.
  if index > 0 then
    ai = 4
  else 
    ai = 2
  end

  totalArea = areaOfTriangle(cell.x[1], cell.y[1], cell.x[ai], cell.y[ai], cell.x[3], cell.y[3])

  -- Check all nodes are visible.
  if cell.state[1] < 0 or cell.state[ai] < 0 or cell.state[3] < 0 then
    return 0.0
  end

  -- Check if all nodes are above threshold.
  if cell.above[1] > 0.5 and cell.above[ai] > 0.5 and cell.above[3] > 0.5 then
    return totalArea
  end

  -- Check if all nodes are below threshold.
  if cell.above[1] < 0.5 and cell.above[ai] < 0.5 and cell.above[3] < 0.5 then
    return 0.0
  end

  -- Cycle nodes.
  for ii = 1,3 do

    ai = ii

    -- Check to wrap next index.
    if ai >= 3 then 
      bi = 1
    else 
      bi = ai+1
    end

    -- Check to wrap next plus one index.
    if bi >= 3 then 
      ci = 1
    else 
      ci = bi+1
    end

    -- Check to invert triangle.
    if index > 0 then
      if ai == 2 then 
        ai = 4
      end
      if bi == 2 then 
        bi = 4
      end
      if ci == 2 then 
        ci = 4
      end
    end

    -- Check if previous and next  segments rise above the threshold.
    if cell.above[ai] > 0.5 and cell.above[bi] < 0.5 and cell.above[ci] > 0.5 then

      Ax = Interpolate(threshold, cell.value[bi], cell.value[ai], cell.x[bi], cell.x[ai])
      Ay = Interpolate(threshold, cell.value[bi], cell.value[ai], cell.y[bi], cell.y[ai])

      Cx = Interpolate(threshold, cell.value[bi], cell.value[ci], cell.x[bi], cell.x[ci])
      Cy = Interpolate(threshold, cell.value[bi], cell.value[ci], cell.y[bi], cell.y[ci])

      area = areaOfTriangle(Ax, Ay, cell.x[bi], cell.y[bi], Cx, Cy)
      return totalArea - area

    end

    -- Check if previous and next  segments dip below the threshold.
    if cell.above[ai] < 0.5 and cell.above[bi] > 0.5 and cell.above[ci] < 0.5 then

      Ax = Interpolate(threshold, cell.value[bi], cell.value[ai], cell.x[bi], cell.x[ai])
      Ay = Interpolate(threshold, cell.value[bi], cell.value[ai], cell.y[bi], cell.y[ai])

      Cx = Interpolate(threshold, cell.value[bi], cell.value[ci], cell.x[bi], cell.x[ci])
      Cy = Interpolate(threshold, cell.value[bi], cell.value[ci], cell.y[bi], cell.y[ci])

      area = areaOfTriangle(Ax, Ay, cell.x[bi], cell.y[bi], Cx, Cy)
      return area

    end

  end

  return 0.0

end

Finally we need to cycle through the grid and test each cell. As the overhead of continually requesting data from Ecotect is probably a bit greater than simply transferring some values, I chose to shuffle the data along as the loop cycles through the j and k directions in the grid.

-- ================================================
-- CYCLE THROUGH GRID.
-- ================================================

areaAbove = 0
areaTotal = 0

for j = 1, grid.rows-1 do

  cell.value[1] = get("grid.cell", 0, j-1)
  cell.above[1] = isAbove(cell.value[1], grid.min)
  cell.x[1], cell.y[1] = get("grid.position", 0, j-1)
  cell.state[1] = get("grid.state", 0, j-1)

  cell.value[4] = get("grid.cell", 0, j)
  cell.above[4] = isAbove(cell.value[4], grid.min)
  cell.x[4], cell.y[4] = get("grid.position", 0, j)
  cell.state[4] = get("grid.state", 0, j)

  for i = 1, grid.cols-1 do

    cell.value[2] = get("grid.cell", i, j-1)
    cell.above[2] = isAbove(cell.value[2], grid.min)
    cell.x[2], cell.y[2] = get("grid.position", i, j-1)
    cell.state[2] = get("grid.state", i, j-1)
  
    cell.value[3] = get("grid.cell", i, j)
    cell.above[3] = isAbove(cell.value[3], grid.min)
    cell.x[3], cell.y[3] = get("grid.position", i, j)
    cell.state[3] = get("grid.state", i, j)

    -- Get cell square size.
    dx = cell.x[2] - cell.x[1]
    dy = cell.y[4] - cell.y[1]

    cellAbove = getAreaOfTriangleAboveThreshold(grid.min, 0, cell)
    cellAbove = cellAbove + getAreaOfTriangleAboveThreshold(grid.min, 1, cell)
    areaAbove = areaAbove + cellAbove

    cellTotal = (dx * dy) / 1000.0
    areaTotal = areaTotal + cellTotal

    -- Shuffle values along.
    cell.value[1] = cell.value[2];
    cell.above[1] = cell.above[2];
    cell.state[1] = cell.state[2];
    cell.x[1] = cell.x[2];
    cell.y[1] = cell.y[2];

    cell.value[4] = cell.value[3];
    cell.above[4] = cell.above[3];
    cell.state[4] = cell.state[3];
    cell.x[4] = cell.x[3];
    cell.y[4] = cell.y[3];

  end

end

The results are stored in the variables areaAbove and areaTotal, defined in lines 5 and 6 above. We can then print these out or display them as part of a more complex report.

AttachmentSize
GetGridArea.zip2.17 KB

Coach Outlet are proud with

comment posted by Anonymous (not verified) :: May 11, 2012

Coach Outlet are proud with Discount Coach Colette Bags sale. The Coach Outlet really is made well and definitely will last for many years. Colorful appearance Coach Outlet Online and beauty accessories are the point of Coach Outlet Online. Every professional woman needs a good handbags. You can find the Coach Outlet most suitable bags for you or your friends from our splendid Coach Purses Outlet all the time. It is well understood that Cheap Coach Handbags has become a renowned gift all annual round bring offthe world. A modern morning Coach Factory stylish silhouette in sophisticated sateen ensemble visual element Coach Outlet Online with detachable shoulder strap, Coach Factory Outlet is specifically a luxurious ladylike choice!Every professional woman needs a good handbags.

バーバリー シャツ

comment posted by バーバリー 財布 (not verified) :: May 10, 2012

当店はヨ-ロッパ burberry財布の正規販売代理店から burberryシャツ 女性直接仕入れており burberry 店舗、流通販売コストを削減することで、お客様にお求めやすい価格でご提供できるように努めております。 販売商品は、全商品、新品・正規品であり、100%本物であることを保証いたします。 バーバリー 財布 は、映画「ティファニーで朝食を」や「カサブランカ」でピーター・セラーズ、 バーバリー T シャツ、バーバリー公式サイト オードリー・ヘプバーン、 バーバリー シャツ 女性ハンフリー・ボガート、 burberry T シャツ元英首相ウィンストン・チャーチル、 バーバリー 店舗新素材を生み出しました。 バーバリー シャツは農民が汚れを防ぐために服 バーバリー バッグコーチ バッグ英国王室で愛 burberryシャツされ続けることになります。 バーバリー シャツ 男性英国王室から授与されたものです バーバリー サングラス. バーバリー シャツ 女性 .創業者であるトーマス・バーバリー(Thomas Burberry)は、1835年イギリス・サリー州ブロッカムグリーンで誕生しました。 バーバリー バッグ burberry 財布 は、映画「ティファニーで朝食を」や「カサブランカ」でピーター・セラーズ、 バーバリー T シャツ、バーバリー公式サイト オードリー・ヘプバーン、 burberry T シャツハンフリー・ボガート、 バーバリー バッグ元英首相ウィンストン・チャーチル、ら数々の著名人が愛用したことでも有名 バーバリー 時計 。また、1955年にはエリザベス2世 バーバリー 財布のロイヤルワラントを授かり、 burberry T シャツ1989年には英国皇太子によって認証を授かっており、 バーバリー シャツ 男性 巻き方イギリス王室ご用達でロイヤルの称号を持っています。現在ロゴとして「 バーバリー ワンピース 値段」と「Burberry's」の二つが存在するが、 バーバリー サングラス デザインがクラシカリウで大変人気があります。 burberryサングラスバーバリーでは一番人気がある burberry時計 バーバリーチェックの burberryシャツ 男性長財布や最高品質のソフトカーフレザーにバーバリーチェックのパターンを施した バーバリーウォレットで機能、 burberry T シャツ使いやすさにも優れた秀逸なモデルの バーバリー アウトレット通販店舗 バーバリー 財布などが販売されています。

ナイキ 靴通販

comment posted by ナイキ 靴通販 (not verified) :: May 10, 2012

ダンクsb ラインから新作が登場。1990年代のスケーターファッションからインスパイアを受けたこのモデル ナイキ ダンク SB 。カラーコンビネーションもさることながら絶妙な素材コンビネーション dunk low pro 元祖 が足下に彩りを与えています。インソールにはインスパイアを受けた90sスケータ NIKE (ナイキ) SB DUNK LOW PRO SB ーのイラストが施されています。 air force 1 ホワイト 1985年にノンエアバスケットボールシューズ ナイキ エアプレスト レその歴史が始まった NIKE DUNK ( luna sb nike )。80年代は、カレッジカラーが登場しボーラーに愛され エアマックス 97 、そのスタイリッシュなフォルムと革新的なカラーリングで復刻モデルとしてストリートで爆発的ヒット ナイキ エア リジュビネ 、NIKEのスケートボードライン nike サンダル 2012 にてズームエアを搭載し ナイキ エアプレスト レ が多くのスニーカーファンを魅了 エアマックス95 通販 レ
nike air yeezy 通販位置により違う圧の空気を注入、 ナイキ 靴通販それを透明の窓から見えるようにした靴。「 ナイキ エア プレスト 」はナイキ、ランニング・カテゴリーのトップ・ NIKE AIR PRESTO モデルに与えられていた商品名。1987年、それを透明の窓から見 ナイキ ダンク SB ナイキ 靴通販 エアマックス 97昨年夏にHTMシリーズよりヘッドポーター/NSWにてテスト販売され、 NIKE SOLASOFT サンダル 瞬く間に完売し、 ナイキ エア イージー 話題となったソーラーソフトフォームをソールに内蔵した新感覚クロッグサンダルSOLARSOFT SANDAL nike shoes【2011年最新作】が遂に登場!!アッパーは伸縮性に優れるファイロンアッパーで、 nike靴通販一体成型をすることにより大幅な軽量化を実現しています。

アディダス靴

comment posted by アディダス靴 (not verified) :: May 10, 2012

アディダスイングランド出身の世界的に有名なサッカー選手「 David Beckham(デビット・ベッカム) 」との限定コラボモデル。 「 モデル名 - Buelton Mid DB - 」 『 adidas×David Beckham 』の限定コラボモデルの1足で、アディダス スーパースターオールド感漂うボディーに際立つヒールに入った3本ラインや、存在感のあるロゴヒールパッチ、細部にまでこだアディダス レディースわったインソール裏のメッシュ仕様、アディダス ランニングシューズミッドカットならではのアディダスランニング軽やかながらにしっかりとした履き心地など、アディダス 通販ジャンルを問わず愛用して頂けアディダス シューズる希少なアイテムです。アディダス スタンスミスプレミアムなレザーを使用したシルエットは、アディダス アウトレットこれまで以上に細身で洗練された雰囲気になっています。アディダス CC ライドアディダスのサッカートレーニングシューズとしてフリークからも人気の高いサンバが登場。アディダス スニーカー今作はスポーティーな印象が少ないカジュアルモデル。アディダス 靴綺麗なシルエットに、スーパースター 靴シンプルなローカットなので年齢、アディダス スーパースター メンズスタイル関係なく様々な方にご愛用頂ける1足です。アディダス トップテン東京オリンピックでは、出場選手の10人中8人はアディダス靴を履いていたといわれる程、実績ある名ブランドです。アディダス コートスターサッカーシューズやジョギング、ランニングシューズとしてはもちろんアディダス アディライズ ミッドプロバスケットやオリンピック選手等からも非常に高い評価を得てきたシューズがアディダス(adidas)です。アディダス ハードランド サッカー日本代表のadidas通販ユニフォームもこのアディダス フォーラム ミッドが担当。その品質の良さは文句なしのアディダス スーパースター レディース世界レベルです。adidasスエードとコーデュロイ生地をアッパー全体にバランスよく使い、アディダス SLAPのアディダス CC ライド レザー イメージカラーでもある鮮やかなアクアブルーをアクセントカラーとして使ったとてもカラーバランスのadidas CC Ride良いモデルです。ADIDAS CAMPUS VULC MIDインソールには、SLAPのコラージュアートがプリントされています。激安アディダス

A large number of

comment posted by coach outlet (not verified) :: May 09, 2012

A large number of best-selling Coach Factory Outlet in our Coach Outlet. Coach is one of the world's top handbag brand, which Coach Outlet is a unique high-end women's and men's fashion brand.

Coach Purses Outlet

comment posted by Coach Purses Outlet (not verified) :: May 01, 2012

This is my first opportunity to visit this website. I found some interesting things and I will apply to the development of my blog. Thanks for sharing useful information. Coach Outlet
Coach Outlet Store Online
Coach Outlet Online

nicely written

comment posted by tom03 (not verified) :: Apr 09, 2012

Now you make it easy for me to understand and implement. Thanks for sharing with us. resorts

Coach Outlet are very popular

comment posted by Coach Outlet (not verified) :: May 10, 2012

Coach Outlet are very popular among the people in the whole world. Stylish Coach Outlet with versatile placing on choice, you can enjoy Coach Outlet Online are freshingly different ways of carrying it! Coach Outlet is highly recommended, elegant and eye-catching and easy to accessorize an outfit.The authentic coach outlet really is made well and definitely will last for many years. Cheap Coach Handbags is designed so elegance and it is cheap sale online factory store. Coach Outlet is one of the world's top Louis Vuitton UK brand, which is a unique high-end women's and men's fashion brand. Created from Coach Outlet online high quality leather, Coach Outlet Online is always quilted for sequence to be gorgeous. Like Coach Outlet with concise, durable, style characteristic win the love of consumers. Gorgeous in Coach Outlet Usa beige with a place for everything, you can consider this splendid Coach Baby Bags as an stylish shoulder bag or an adorable crossbody bag. Coach Bags Sale is a leading American designer and maker of luxury lifestyle handbags and accessories for Coach Outlet Online collection of all these will most in all probability be the actuality that while the branded Louis Vuitton Bags combine quality, durability, efficiency.




View desktop or mobile version of site.