Python Forum
[Geometry] Finding centers of each grid in pointgrid
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Geometry] Finding centers of each grid in pointgrid
#3
Hello and thanks for your answer.
I am sorry for the horrible question, hope this is a better representation of it:

The Image function does not work, so I am unable to visually represent what I have so far. (The points and lines in 3D space)

The code so far gets input a list of lines, which create a few grids of lines, and the code finds the lines intersectionspoints to create a pointgrid.

I cannot wrap my head around how to find the centerpoints of each grid (see picture).

The
dataEnteringNode = IN
and the
OUT
are needed for the "Node" to read information into the pythonscript, and output the result back into the Dynamo program.

Dynamo is a visual programming software used for modeling, which has an implemented IronPython node.

Do you have any clue?

Here is the code:
import clr
clr.AddReference('ProtoGeometry')
clr.AddReference('DSCoreNodes') 
import DSCore
from DSCore import *
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
OUT = []

def line_intersects(p1sp,p1ep,p2sp,p2ep):
	xdiff = (p1sp.X - p1ep.X, p2sp.X - p2ep.X)
	ydiff = (p1sp.Y - p1ep.Y, p2sp.Y - p2ep.Y)
	
	def det(a1,a2,b1,b2):
		return a1 * b2 - a2 * b1
	
	div = det(xdiff[0],xdiff[1],ydiff[0],ydiff[1])
	if div <> 0:
		d = (det(p1sp.X,p1sp.Y,p1ep.X,p1ep.Y), det(p2sp.X,p2sp.Y,p2ep.X,p2ep.Y))
		x = det(d[0],d[1], xdiff[0],xdiff[1]) / div
		y = det(d[0],d[1], ydiff[0],ydiff[1]) / div
		if x > p1sp.X and x < p1ep.X and y > p2sp.Y and y < p2ep.Y:
			return Point.ByCoordinates(x,y)
			
for l1 in IN[0]:
	p1sp = l1.StartPoint 
	p1ep = l1.EndPoint
	data = []
	for l2 in IN[0]:
		if l1 <> l2:
			p2sp = l2.StartPoint
			p2ep = l2.EndPoint
			if  p1sp.X < p2sp.X and p1ep.X > p2ep.X  or p1sp.Y > p2sp.Y and p1ep.Y < p2ep.Y:
				if not (line_intersects(p1sp,p1ep,p2sp,p2ep) is None):
					data.append(line_intersects(p1sp,p1ep,p2sp,p2ep))
	if data.Count > 0:
		OUT.append([l1,data])
Reply


Messages In This Thread
RE: [Geometry] Finding centers of each grid in pointgrid - by andre - Aug-22-2017, 12:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  finding point in m grid jenya56 0 1,247 Feb-06-2022, 09:00 PM
Last Post: jenya56
  Import Text, output curve geometry Alyner 0 2,465 Feb-03-2020, 03:05 AM
Last Post: Alyner
  How do I apply a Gaussian blur to a particular edge of geometry in Matplotlib? hbolandi 0 2,613 Feb-02-2020, 06:08 PM
Last Post: hbolandi
  terminal/console geometry Skaperen 12 11,740 Feb-02-2017, 02:09 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020