Select to view content in your preferred language

Split face into rectangular pieces

971
4
02-10-2023 06:32 AM
MagnusLundevall
Emerging Contributor

I have a planar face that I want to split along x into rectangular pieces, see enclosed figure. I have tried to examine the pivot pos of the edges with comp(fe) to find the x-positions for the split but without full success. 

Any suggestions for solution in CGA code? Is the question clear enough?

Tags (1)
4 Replies
ThomasFuchs
Esri Regular Contributor

Hello @MagnusLundevall 

Thanks for this interesting question. Please try this approach using comp(v) and sorting the vertices by their pivot.px

version "2022.1"

XPos = comp(v) { all : pivot.px }

SortedXPos = 
	XPos[sortIndices(XPos)]

const EPS = 0.01
calcNextVertexLoc(positions, i) =
	case i < geometry.nVertices:
		case abs(positions[i] - positions[0]) < EPS: calcNextVertexLoc(positions, i+1) // check next vertex position
		else: positions[i] - positions[0]
	else: scope.sx
	
getSplitPos =
	calcNextVertexLoc(SortedXPos, 2)

@StartRule
SplitRecursive -->
	split(x) { getSplitPos : Rectangle | ~1 : SplitRecursive }
	
Rectangle --> color(rand, rand, rand)

 

0 Kudos
MagnusLundevall
Emerging Contributor

Thanks for quick response. This is along the lines I have tried but much more elegant. It works in general but not for faces in certain orientations. I suspect I need to align the scope in some way. Any advice here?

To isolate the orientation problem I have made a simple shape where I try to apply SplitRecursive for each side face. Seems not possible to attach a scene here so I give the shape vertices instead. I have tried various kind of alignScope but without success.

MagnusLundevall_0-1676440871742.png

 

 

 

 

@StartRule
Init -->
	comp(f) {side: SplitRecursive | all: NIL} 

 

 

 

Here is the current result. In this simple example I expect one Rectangle for each face.

MagnusLundevall_1-1676441020181.png

 




0 Kudos
ThomasFuchs
Esri Regular Contributor

The approach only works for horizontal and planar Shapes like building footprints. The axis of pivot and scope must be aligned.

Generally, rectangles can be created with the innerRectangle operation.

0 Kudos
MagnusLundevall
Emerging Contributor

Oh, what a pitty. And there is no way to align the scope such that it can work?

I read about innerRectangle but don't see how it can be used to solve the example in the first post. Can you?

0 Kudos