# Points distribution in surface

**URL:** <https://forum.dynamobim.com/t/points-distribution-in-surface/19301>\
**Category:** Geometry\
**Created:** [February 21, 2018, 6:18pm UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301 "2018-02-21T18:18:15Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricardoperucci](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@ricardoperucci](https://forum.dynamobim.com/u/ricardoperucci)\
**Post date:** [February 21, 2018, 6:18pm UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/1 "2018-02-21T18:18:15Z")

</div>

Hi there,  
I am trying to create a bunch of point, equally separated (like a grid) on a surface. Firstly I create the surface, then I subtract lots of solids from it, so at the end I have a surface with lots of “holes”. After that I want to have a distribution of points that are inside the remaining surface.  
I thought about creating these points in a big area (bigger than the whole surface) and then getting only those that intersect this surface, however this is getting my running too slow. I was wondering if anyone has any idea of how could I have those points without having to create all of them and then getting those which have intersection with the surface, something like creating points only where the surface exists, so I dont have to create so much points and then remove them.  
Another problem is that I have lots of surfaces in a list, so each of them are in different places at the drawing so I must create these points at certains areas of the CoordinateSystem.  
I don’t know if I could be clear on my explaining, so I’ve screen printed an example of how I am doing it now, so you can understand better what I want to have at the end. Any help would be appreciated.

Thanks!

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/d/3daf2f0eed60b2f328ba5270e15795c0e5b410f1.png)

---

<div class="post-metadata">

**Author:** ![BenjaminDoty](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@BenjaminDoty](https://forum.dynamobim.com/u/BenjaminDoty)\
**Post date:** [February 21, 2018, 8:31pm UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/2 "2018-02-21T20:31:43Z")

</div>

Like this?

 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/b/db6e0bf7749650d398d9238733b8aa4f3fdd8a0d.png)

---

<div class="post-metadata">

**Author:** ![BenjaminDoty](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@BenjaminDoty](https://forum.dynamobim.com/u/BenjaminDoty)\
**Post date:** [February 21, 2018, 8:32pm UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/3 "2018-02-21T20:32:44Z")

</div>

This is a better image.

 ![2018-02-21_12-32-05](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/a/0a96847a87d13b82252e973b4573040edfb47972.jpg)

---

<div class="post-metadata">

**Author:** ![ricardoperucci](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@ricardoperucci](https://forum.dynamobim.com/u/ricardoperucci)\
**Post date:** [February 21, 2018, 8:35pm UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/4 "2018-02-21T20:35:29Z")

</div>

Hi @BenjaminDoty, thanks for your reply!  
Actually, this is exactly what I am trying to avoid… In your method, I would still have to create plenty of points that are going to be discarded, almost the same as mine, and that is slowing down the running process.

Thanks anyway!

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [February 22, 2018, 2:01am UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/5 "2018-02-22T02:01:26Z")

</div>

I can’t think of another method to do this. If you create the points and check them for intersection in a single code line it shouldn’t slow you down too much.

---

<div class="post-metadata">

**Author:** ![ricardoperucci](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@ricardoperucci](https://forum.dynamobim.com/u/ricardoperucci)\
**Post date:** [February 22, 2018, 3:00pm UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/6 "2018-02-22T15:00:21Z")

</div>

I was thinking about something that could “split” a surface on a defined number of points maybe… I will try to optimize what I am doing now.  
Thanks

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [February 23, 2018, 2:16am UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/7 "2018-02-23T02:16:33Z")

</div>

Would a UV grid be helpful here or are you trying to get the same grid regardless of the surface shape?

---

<div class="post-metadata">

**Author:** ![ricardoperucci](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@ricardoperucci](https://forum.dynamobim.com/u/ricardoperucci)\
**Post date:** [February 23, 2018, 1:32pm UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/8 "2018-02-23T13:32:28Z")

</div>

I don’t really know which node is that, but it seems to be a great thing… Can you explain more? I cannot find it here!

---

<div class="post-metadata">

**Author:** ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)\
**Post date:** [February 23, 2018, 5:00pm UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/9 "2018-02-23T17:00:08Z")

</div>

@ricardoperucci Here is a distribution, not equally separated, but doesn’t create points beyond the surface  
[SurfacePoints.dyn](https://forum.dynamobim.com/uploads/short-url/vWTLfHskWLoPyfXo6XoyrTYbgZA.dyn) (8.5 KB)

 ![SurfacePoints](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/d/4d4d8db37d6b41f47da186d8a83740f1bfbafae3.png)

---

<div class="post-metadata">

**Author:** ![ricardoperucci](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@ricardoperucci](https://forum.dynamobim.com/u/ricardoperucci)\
**Post date:** [February 23, 2018, 5:03pm UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/10 "2018-02-23T17:03:14Z")

</div>

That is closer to what I wanted to do! Thank you all for your replies, but I am doing it by creating a rectangular distribution of points (a rectangle that contains the whole surface) and then projecting them on the surface, all inside python. Doing it this way is actually not slowing down my running that much.  
Thanks!!

---

<div class="post-metadata">

**Author:** ![ricardoperucci](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@ricardoperucci](https://forum.dynamobim.com/u/ricardoperucci)\
**Post date:** [February 23, 2018, 5:09pm UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/11 "2018-02-23T17:09:14Z")

</div>

This is what I’ve written, not sure if anyone are going to understand, but just for sharing…  
My script uses a class instance that I’ve created before, “objetoDesenho”. From there I get some specific points, vectors, dimensions and list of objects to compare for this script specifically…

> Blockquote

objetoDesenho= IN[0]  
alturaRetangulo = IN[1]  
folgaLateral = IN[2]  
alturaPoligonoPosicao = IN[3]

listaPontos =   
listaPontosSaida =

```
	ponto1Central = Point.Add(objetoDesenho.pontoTexto, Vector.Scale(Vector.Reverse(objetoDesenho.vetorDireita()), folgaLateral))

	ponto4Ret = Point.Add(ponto1Central, Vector.Scale(objetoDesenho.vetorDesvioLabel(), alturaRetangulo/2))
	ponto3Ret = Point.Add(ponto4Ret, Vector.Scale(objetoDesenho.vetorDireita(), (2*folgaLateral + objetoDesenho.tamanhoTexto)))
	ponto2Ret = Point.Add(ponto3Ret, Vector.Scale(Vector.Reverse(objetoDesenho.vetorDesvioLabel()), alturaRetangulo))
	ponto1Ret = Point.Add(ponto2Ret, Vector.Scale(Vector.Reverse(objetoDesenho.vetorDireita()), (2*folgaLateral + objetoDesenho.tamanhoTexto)))

	retanguloInteiro = Rectangle.ByCornerPoints(ponto1Ret, ponto2Ret, ponto3Ret, ponto4Ret)
	superficieRetangulo = Surface.ByPatch(retanguloInteiro)
	solidoObjetoDesenho = Surface.Thicken(objetoDesenho.superficie(), 1)
	superficieRetangulo = Surface.SubtractFrom(superficieRetangulo, solidoObjetoDesenho)[0]

	#REMOVER AS SUPERFICIES DOS OBJETOS PERTOS E DOS LABELS POSICIONADOS

	k = len(objetoDesenho.listaObjetoPerto) - 1
	contador = 0
	while k >= 0 and contador < 300:

		objetoOutro = objetoDesenho.listaObjetoPerto[k]
		
		solidoObjeto = Surface.Thicken(Surface.ByPatch(objetoOutro.polyCurve), 1)
		superficieRetangulo = Surface.SubtractFrom(superficieRetangulo, solidoObjeto)[0]
		
		if objetoOutro.jaPosicionada:
			
			solidoTexto = Surface.Thicken(Surface.ByPatch(objetoOutro.poligonoTexto), 1)
			solidoPosicao = Surface.Thicken(Surface.ByPatch(objetoOutro.poligonoPosicao), 1)

			superficieRetangulo = Surface.SubtractFrom(superficieRetangulo, solidoTexto)[0]
			superficieRetangulo = Surface.SubtractFrom(superficieRetangulo, solidoPosicao)[0]

		contador += 1
		k = k - 1

	listaRetangulos.Add(superficieRetangulo)
	
	pontoOrigemCS = Point.Add(objetoDesenho.pontoTexto, Vector.Scale(objetoDesenho.vetorDireita(), objetoDesenho.tamanhoTexto/2))
	
	vetorCS = Vector.Cross(objetoDesenho.vetorDireita(), vetorZN)
	if Vector.Dot(vetorCS, objetoDesenho.vetorDesvioLabel()) < 0:
		
		vetorCS = Vector.Reverse(vetorCS)
	
	objetoCS = CoordinateSystem.ByOriginVectors(pontoOrigemCS, objetoDesenho.vetorDireita(), vetorCS)

	x0 = 0
	y0 = objetoDesenho.alturaTexto + 0.5*alturaPoligonoPosicao
	
	xf = 0.5*objetoDesenho.tamanhoTexto + folgaLateral
	yf = 0.5*(alturaRetangulo)
	
	x = x0
	
	contador = 0
	while x < xf and contador < 2000:
	
		if contador % 2 == 0:
			
			x = x + 10*contador
		else:
			x = x - 10*contador
			
		contador2 = 0
		y = y0
		while y < yf and contador2 < 2000:
			
			y = y0 + 10*contador2
			
			listaPontos.Add(Point.ByCoordinates(x,y))
			contador2 += 1
			
		contador += 1

	xN0 = x0
	yN0 = - 0.5*alturaPoligonoPosicao

	xNf = xf
	yNf = - yf

	x = xN0

	contador3 = 0
	while x < xNf and contador3 < 2000:
	
		if contador3 % 2 == 0:
			
			x = x + 10*contador3
		else:
			x = x - 10*contador3
			
		contador4 = 0
		y = yN0
		while y > yNf and contador4 < 2000:
			
			y = y0 - 10*contador4
			
			listaPontos.Add(Point.ByCoordinates(x,y))
			contador4 += 1
			
		contador3 += 1
	
	for ponto in listaPontos:
		
		pontoSaida = Geometry.Transform(ponto, objetoCS)
		pontoSaida = Point.ByCoordinates(pontoSaida.X, pontoSaida.Y, 10)
		
		projecao = pontoSaida.Project(superficieRetangulo, vetorZN)
		
		if len(projecao) == 1:
			
			listaPontosSaida.Add(projecao[0])

```

---

<div class="post-metadata">

**Author:** ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)\
**Post date:** [February 23, 2018, 5:14pm UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/12 "2018-02-23T17:14:53Z")

</div>

> [@ricardoperucci](#):
>
> creating a rectangular distribution of points (a rectangle that contains the whole surface) and then projecting them on the surface, all inside python

You could use _Surface.PointAtParameter_ to do this

[SurfacePoints1.dyn](https://forum.dynamobim.com/uploads/short-url/7zF5U5g5cPgXJlINTAal7Ho32Jf.dyn) (11.4 KB)

 ![SurfacePoints1](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/0/60b5394033605bfc95131b052a7af931749c38c6.png)

---

<div class="post-metadata">

**Author:** ![ricardoperucci](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@ricardoperucci](https://forum.dynamobim.com/u/ricardoperucci)\
**Post date:** [February 23, 2018, 6:05pm UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/13 "2018-02-23T18:05:07Z")

</div>

Nice!

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [February 23, 2018, 11:39pm UTC](https://forum.dynamobim.com/t/points-distribution-in-surface/19301/14 "2018-02-23T23:39:00Z")

</div>

I’ve been thinking about this a bit - here are some thoughts:

agents:  
generate points via agents which move on the surface and pick the directions they move based on past information (where are we failing to find intersections)

divide and conquer:  
split the surface into subsurfaces and apply points to these smaller portions, this could be multithreaded potentially.

multithreaded:  
try using c# or python and do a multithreaded foreach loop where you divide the list of initial points into some sub lists.

project lines instead:  
project curves and then evaluate those instead.
