18 Aug, 2019

More on The Bounding Box With EKL…

Hi All!

Sometime back I had created a powercopy for generating bounding boxs for 3D surfaces. Seeing Maher’s post, I thought of sharing what I had done and also some EKL scripts for achieving the same.

There are two possibilities here:

  • A bounding box based on computed inertia axes.
  • A bounding box based on a user provided axis system.

I have added some callouts in the video below, which should hopefully describe the approach.

And here are the scripts for reference:

Bounding Box with computed Inertia Axis System

/* Action created by U23 18-Aug-19 */

let iA1, iA2, iA3 (line)
iA1 = inertiaAxis(1, s)
iA2 = inertiaAxis(2, s)
iA3 = inertiaAxis(3, s)

let e1max, e1min, e2max, e2min, e3max, e3min, cog (point)

cog = centerofgravity(s)

e1max = extremum(s, direction(iA1), True, direction(iA2), True, direction(iA3), True )  
e1min =  extremum(s, direction(iA1), False, direction(iA2), True, direction(iA3), True )  

e2max = extremum(s, direction(iA2), True, direction(iA1), True, direction(iA3), True )  
e2min =  extremum(s, direction(iA2), False, direction(iA1), True, direction(iA3), True )  

e3max = extremum(s, direction(iA3), True, direction(iA2), True, direction(iA1), True )  
e3min =  extremum(s, direction(iA3), False, direction(iA2), True, direction(iA1), True )  

let pl1, pl2, pl3, ple1max, ple1min, ple2max, ple2min, ple3max, ple3min (plane)

pl1 =planenormal(iA1, cog)
pl2 = planenormal(iA2, cog)
pl3 = planenormal(iA3, cog)

ple1max = planeoffset (pl1, e1max)
ple1min = planeoffset (pl1, e1min)
ple2max = planeoffset (pl2, e2max)
ple2min = planeoffset (pl2, e2min)
ple3max = planeoffset (pl3, e3max)
ple3min = planeoffset (pl3, e3min)

let l1, l2, l3, l4 (line)
set l1 = intersect(ple1max, ple2max)
set l2 = intersect(ple1max, ple2min)
set l3 = intersect(ple1min, ple2min)
set l4 = intersect(ple1min, ple2max)

let v1, v2, v3, v4, v5, v6, v7, v8 (point)
set v1 = intersect(l1, ple3max)
set v2 = intersect(l2, ple3max)
set v3 = intersect(l3, ple3max)
set v4 = intersect(l4, ple3max)

set v5 = intersect(l1, ple3min)
set v6 = intersect(l2, ple3min)
set v7 = intersect(l3, ple3min)
set v8 = intersect(l4, ple3min)

let face1, face2, face3, face4, face5, face6, box (surface)

face1 = fill(List(line(v1, v2), line(v2, v3), line(v3, v4), line(v4, v1)))
face2 = fill(List(line(v5, v6), line(v6, v7), line(v7, v8), line(v8, v5)))
face3 = fill(List(line(v1, v5), line(v5, v6), line(v6, v2), line(v2, v1)))
face4 = fill(List(line(v2, v6), line(v6, v7), line(v7, v3), line(v3, v2)))
face5 = fill(List(line(v7, v3), line(v3, v4), line(v4, v8), line(v8, v7)))
face6 = fill(List(line(v5, v1), line(v1, v4), line(v4, v8), line(v8, v5)))

box = new("Surface", s.Name + "_BoundingBox", PartBody)
set box = assemble(List(face1, face2, face3, face4, face5, face6))

box.Color = "red"
box.Transparency = 150
box.Update()

Bounding Box with user defined Axis System

/* Action created by U23 18-Aug-19 */
let m (matrix)
m = a .Axes 

let vec1, vec2, vec3, vec0(vector)
vec0 = a.Origin
vec1 = m.GetLine(1)
vec2 = m.GetLine(2)
vec3 = m.GetLine(3)

let e1max, e1min, e2max, e2min, e3max, e3min, cog (point)
cog = point(vec0.Get(1, 1), vec0.Get(1, 2), vec0.Get(1, 3))

let d1, d2, d3 (direction)
d1 = vec1.Direction()
d2 = vec2.Direction()
d3 = vec3.Direction()

let iA1, iA2, iA3 (line)
iA1 =  line(cog, d1, 100m,-100m, true)
iA2 =  line(cog, d2, 100m,-100m, true)
iA3 =  line(cog, d3, 100m,-100m, true)

e1max = extremum(s, direction(iA1), True, direction(iA2), True, direction(iA3), True )  
e1min =  extremum(s, direction(iA1), False, direction(iA2), True, direction(iA3), True )  

e2max = extremum(s, direction(iA2), True, direction(iA1), True, direction(iA3), True )  
e2min =  extremum(s, direction(iA2), False, direction(iA1), True, direction(iA3), True )  

e3max = extremum(s, direction(iA3), True, direction(iA2), True, direction(iA1), True )  
e3min =  extremum(s, direction(iA3), False, direction(iA2), True, direction(iA1), True )  

let pl1, pl2, pl3, ple1max, ple1min, ple2max, ple2min, ple3max, ple3min (plane)

pl1 =planenormal(iA1, cog)
pl2 = planenormal(iA2, cog)
pl3 = planenormal(iA3, cog)

ple1max = planeoffset (pl1, e1max)
ple1min = planeoffset (pl1, e1min)
ple2max = planeoffset (pl2, e2max)
ple2min = planeoffset (pl2, e2min)
ple3max = planeoffset (pl3, e3max)
ple3min = planeoffset (pl3, e3min)

let l1, l2, l3, l4 (line)
set l1 = intersect(ple1max, ple2max)
set l2 = intersect(ple1max, ple2min)
set l3 = intersect(ple1min, ple2min)
set l4 = intersect(ple1min, ple2max)

let v1, v2, v3, v4, v5, v6, v7, v8 (point)
set v1 = intersect(l1, ple3max)
set v2 = intersect(l2, ple3max)
set v3 = intersect(l3, ple3max)
set v4 = intersect(l4, ple3max)

set v5 = intersect(l1, ple3min)
set v6 = intersect(l2, ple3min)
set v7 = intersect(l3, ple3min)
set v8 = intersect(l4, ple3min)

let face1, face2, face3, face4, face5, face6, box (surface)

face1 = fill(List(line(v1, v2), line(v2, v3), line(v3, v4), line(v4, v1)))
face2 = fill(List(line(v5, v6), line(v6, v7), line(v7, v8), line(v8, v5)))
face3 = fill(List(line(v1, v5), line(v5, v6), line(v6, v2), line(v2, v1)))
face4 = fill(List(line(v2, v6), line(v6, v7), line(v7, v3), line(v3, v2)))
face5 = fill(List(line(v7, v3), line(v3, v4), line(v4, v8), line(v8, v7)))
face6 = fill(List(line(v5, v1), line(v1, v4), line(v4, v8), line(v8, v5)))

box = new("Surface", s.Name + "_BoundingBox_AxisSystem", PartBody)
set box = assemble(List(face1, face2, face3, face4, face5, face6))

box.Color = "blue"
box.Transparency = 150
box.Update()
Tags: , ,

About : Rohan Keswani

Rohan works in the CATIA Portfolio Management team at Dassault Systemes and handles activities related to knowledgeware roles, EKL and design automation.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.