Now that the user interface for the concrete tool is up and running, I need to start working on the concrete analysis.

The first order of business is a meshing algorithm for the concrete shape. 

I do not know exactly which direction this meshing algorithm is going to head, but every direction I look, it appears as though I will need some code to check if a given point falls within an enclosed polygon. The pretty pictures above show the code in action, if the point falls within the polygon, it is painted green, if not, red.

After some research, it appeared as though the ray caster algorithm would be the ticket to solve this problem. 

The code to check if the point falls within any given abritary polygon is shown below:

function ray_casting(point, testPoly, holePolys) {
  var n = testPoly.length;
  var count = 0
  var holeCount = 0
  var x = point[0];
  var y = point[1];
  

for(var i=0; i <n; ++i) {
    if (i == n-1) {
      var side = {
        a: {
          x: testPoly[i][0],
          y: testPoly[i][1]
        },
        b: {
          x: testPoly[0][0],
          y: testPoly[0][1]
        }
      }
        var x1 = side.a.x
        var x2 = side.b.x
        var y1 = side.a.y
        var y2 = side.b.y
        if (y < y1 != y < y2 && x < (x2-x1)*(y-y1)/ (y2-y1)+x1) {
        count +=1
      }
    }
    else {
      var side = {
        a: {
          x: testPoly[i][0],
          y: testPoly[i][1]
        },
        b: {
          x: testPoly[i+1][0],
          y: testPoly[i+1][1]
        }
      }
      var x1 = side.a.x
      var x2 = side.b.x
      var y1 = side.a.y
      var y2 = side.b.y
      if (y < y1 != y < y2 && x < (x2-x1)*(y-y1)/ (y2-y1)+x1) {
        count +=1
      }
    }
  }
  for (var holePoly of holePolys) {
    var nHole = holePoly.length;
    for(var i=0; i <nHole; ++i) {
      if (i ==nHole-1){
        var side = {
          a: {
            x: holePoly[i][0],
            y: holePoly[i][1]
          },
          b: {
            x: holePoly[0][0],
            y: holePoly[0][1]
          }
        }
        var x1 = side.a.x
        var x2 = side.b.x
        var y1 = side.a.y
        var y2 = side.b.y
        if (y < y1 != y < y2 && x < (x2-x1)*(y-y1)/ (y2-y1)+x1) {
          holeCount +=1
        }
      }
      else{
        var side = {
          a: {
            x: holePoly[i][0],
            y: holePoly[i][1]
          },
          b: {
            x: holePoly[i+1][0],
            y: holePoly[i+1][1]
          }
        }
        var x1 = side.a.x
        var x2 = side.b.x
        var y1 = side.a.y
        var y2 = side.b.y
        if (y < y1 != y < y2 && x < (x2-x1)*(y-y1)/ (y2-y1)+x1) {
          holeCount +=1
        }
      }
    }
  }
  if (count % 2 == 0 || count == 0 ) {
    return [false, count, holeCount]
  }
  else if (holeCount % 2 == 1) {
    return [false, count, holeCount]
  }
  else {
    return [true, count, holeCount]
  }
}

The algorithm is very simple, given a point, cast an inifinite line to the right. If the line crosses the polygon an even number of times, the point is outside the polygon.

Adding in some more code to test for holes and we are able to quickly tell if the point is inside or outisde the polygon with holes.

The code can be found on github.

A tease for the future:

Reinforced Concrete Javascript

Our Sidebar

You can put any information here you'd like.

  • Latest Comments
  • retug on ETABs Parametric Building -

    @Toni, this post does not discuss the level of mesh refinement required. The focus is on building an ETABS model efficiently. Mesh refinement is typically evaluated within ETABS by studying the parameter of interest and refining the mesh until the results converge to an acceptable tolerance.

    @fpsstructures, I edited your …

  • fpsstructures on ETABs Parametric Building -

    Really impressive work combining Three.js with ETABS for a parametric workflow. The ability to quickly generate and analyze multiple tower forms can be a huge advantage during early-stage design exploration. I also like how the structural logic still feels clean and efficient despite the complex geometry. 

  • Toni on ETABs Parametric Building -

    How do you assess the fineness of the mesh required? More scale or load based?