# Forum

### Author Topic: resize bounding box to sparse point cloud  (Read 19666 times)

#### Seboon

• Jr. Member
• Posts: 72
##### Re: resize bounding box to sparse point cloud
« Reply #15 on: January 16, 2018, 08:24:20 PM »
Thanks Alexey,

I was suspecting it was something like that.
Maybe you have in your magic luggage an already existing "pythonesc"  formula for this kind of calculation : Axe of the mesh compared to the North (0°), resulting in  a rotation degrees  to apply on the Bbox?

As a workaround, i use a mix of your both scipts"BBox to CRS" and "CRS to BBox", see attached script.

Thanks for any suggestion for improving it, escpecillay with the magic formula :-)

Best regards!
S.Poudroux
Archaeologist - Topographer - Drone remote pilot

#### Alexey Pasumansky

• Agisoft Technical Support
• Hero Member
• Posts: 14968
##### Re: resize bounding box to sparse point cloud
« Reply #16 on: January 16, 2018, 08:51:43 PM »
Hello Seboon,

Do you mean manual (custom) rotation from the Northing direction?
Best regards,
Alexey Pasumansky,
Agisoft LLC

#### Seboon

• Jr. Member
• Posts: 72
##### Re: resize bounding box to sparse point cloud
« Reply #17 on: March 02, 2018, 11:17:13 AM »
Hello Alexey,

Yeah I suppose it's this kind of idea.
Also drawing a temporary line shape with two points could indicate the difference azimuth to apply.
Thanks in any case!
S.Poudroux
Archaeologist - Topographer - Drone remote pilot

#### chitty1989

• Newbie
• Posts: 20
##### Re: resize bounding box to sparse point cloud
« Reply #18 on: March 17, 2022, 04:20:18 AM »
Hello Susann,

For the unreferenced chunks it should be shorter:
Code: [Select]
`import PhotoScan, mathdoc = PhotoScan.app.documentchunk = doc.chunkregion = chunk.regionT = chunk.transform.matrixm = PhotoScan.Vector([10E+10, 10E+10, 10E+10])M = -mfor point in chunk.point_cloud.points: if not point.valid: continue coord = T * point.coord for i in range(3): m[i] = min(m[i], coord[i]) M[i] = max(M[i], coord[i]) center = (M + m) / 2size = M - mregion.center = T.inv().mulp(center)region.size = size * (1 / T.scale())region.rot = T.rotation().t()chunk.region = regionprint("Script finished.")`

Hey Alexey,

Is there any way I can run this script as part of a batch?  At the moment the batch stops at the first chunk and doesnt run the script through the rest of the chunks!