# How to control the orientation of box entity

**URL:** <https://community.cesium.com/t/how-to-control-the-orientation-of-box-entity/6645>\
**Category:** CesiumJS\
**Created:** [March 8, 2018, 7:51pm UTC](https://community.cesium.com/t/how-to-control-the-orientation-of-box-entity/6645 "2018-03-08T19:51:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aasim\_Kamal](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@Aasim\_Kamal](https://community.cesium.com/u/Aasim_Kamal)\
**Post date:** [March 8, 2018, 7:51pm UTC](https://community.cesium.com/t/how-to-control-the-orientation-of-box-entity/6645/1 "2018-03-08T19:51:41Z")

</div>

**1. A concise explanation of the problem you’re experiencing.**

I am trying to build bounding boxes along my flight path in order to build a 3D corridor. I am not able to control the orientation of the boxes as my boxes should be centered around each path and orient according to the curves or altitude variations.

**2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.**

var viewer = new Cesium.Viewer(‘cesiumContainer’);

//Use STK World Terrain

viewer.terrainProvider = new Cesium.CesiumTerrainProvider({

url : ‘[https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles](https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles)’,

requestVertexNormals : true

});

//Set the random number seed for consistent results.

Cesium.Math.setRandomNumberSeed(3);

var start = Cesium.JulianDate.fromDate(new Date());

var stop = Cesium.JulianDate.addSeconds(start, 360, new Cesium.JulianDate());

var a = ;

var b = ;

function computeFlightPath(lon, lat, radius, index) {

var count = 0;

var pos = new Cesium.SampledPositionProperty();

for (var i = 0; i \<= 270; i += 15) {

var radians = Cesium.Math.toRadians(i);

console.log(radians);

var time = Cesium.JulianDate.addSeconds(start, i, new Cesium.JulianDate());

var position = Cesium.Cartesian3.fromDegrees(lon + (radius \* 1.5 \* Math.cos(radians)), lat + (radius \* Math.sin(radians)), Cesium.Math.nextRandomNumber() \* 500 + 1750);

pos.addSample(time, position);

if(index === 1){

a[count] = pos.getValue(time);

}

if(index === 2) {

b[count] = pos.getValue(time);

}

//Also create a point for each sample we generate.

if(index === 1) {

viewer.entities.add({

position : position,

point : {

pixelSize : 8,

color : Cesium.Color.TRANSPARENT,

outlineColor : Cesium.Color.YELLOW,

outlineWidth : 3

}

});

}

if(index === 2) {

viewer.entities.add({

position : position,

point : {

pixelSize : 8,

color : Cesium.Color.TRANSPARENT,

outlineColor : Cesium.Color.RED,

outlineWidth : 3

}

});

}

count++;

}

return pos;

}

function computeFinalFlightPath(d, a, b) {

console.log(a);

var property = new Cesium.SampledPositionProperty();

for (var i = 0; i \< a.length; i++) {

var radians = Cesium.Math.toRadians(i\*15);

[//console.log](https://console.log)(radians);

var time = Cesium.JulianDate.addSeconds(start, i, new Cesium.JulianDate());

var position = Cesium.Cartesian3.fromElements(((a[i].x+b[i].x)/2), ((a[i].y+b[i].y)/2), ((a[i].z+b[i].z)/2));

property.addSample(time, position);

//Also create a point for each sample we generate.

viewer.entities.add({

position : position,

point : {

pixelSize : 8,

color : Cesium.Color.TRANSPARENT,

outlineColor : Cesium.Color.CYAN,

outlineWidth : 3

}

});

viewer.entities.add({

position: position,

box : {

dimensions : new Cesium.Cartesian3(400.0, 300.0, 500.0),

fill : false,

outline : true,

outlineColor : Cesium.Color.BLUE

}

});

}

return property;

}

//Compute the position

var position = computeFlightPath(-83.60986232757568,41.653258658953995, 0.03, 1);

var position1 = computeFlightPath(-83.60986232757570,41.653258658953998, 0.033, 2);

var d = ;

for(i=0;i\<a.length;i++){

d[i] = Cesium.Cartesian3.distance(a[i], b[i]);

}

[//console.log](https://console.log)(d);

[//console.log](https://console.log)(a);

[//console.log](https://console.log)(b);

var positionFinal = computeFinalFlightPath(d,a,b);

var entity = viewer.entities.add({

availability : new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({

start : start,

stop : stop

})]),

//Use our computed positions

position : position,

//Automatically compute orientation based on position movement.

orientation : new Cesium.VelocityOrientationProperty(position),

path : {

resolution : 1,

material : new Cesium.PolylineGlowMaterialProperty({

glowPower : 0.1,

color : Cesium.Color.YELLOW

}),

width : 10

}

});

var entity1 = viewer.entities.add({

availability : new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({

start : start,

stop : stop

})]),

//Use our computed positions

position : position1,

//Automatically compute orientation based on position movement.

orientation : new Cesium.VelocityOrientationProperty(position),

path : {

resolution : 1,

material : new Cesium.PolylineGlowMaterialProperty({

glowPower : 0.1,

color : Cesium.Color.RED

}),

width : 10

}

});

var entity2 = viewer.entities.add({

availability : new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({

start : start,

stop : stop

})]),

//Use our computed positions

position : positionFinal,

//Automatically compute orientation based on position movement.

orientation : new Cesium.VelocityOrientationProperty(position),

path : {

resolution : 1,

material : new Cesium.PolylineGlowMaterialProperty({

glowPower : 0.1,

color : Cesium.Color.CYAN

}),

width : 10

}

});

viewer.zoomTo(viewer.entities);

**3. Context. Why do you need to do this? We might know a better way to accomplish your goal.**

I want to build a 3D shape corridor. However, I want to start building a bounding box around each point. Later, I would like to interpolate the geometry to form a 3D shaped corridor. Please help!

**4. The Cesium version you’re using, your operating system and browser.**

Cesium - 1.42, Windows 10, Mozilla Firefox

 ![Capture.PNG](https://global.discourse-cdn.com/cesium/original/1X/76e3764b7dbc2e694e01fb5ffb99b1b3cf01efc2.png)

---

<div class="post-metadata">

**Author:** ![Aasim\_Kamal](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@Aasim\_Kamal](https://community.cesium.com/u/Aasim_Kamal)\
**Post date:** [March 10, 2018, 9:16pm UTC](https://community.cesium.com/t/how-to-control-the-orientation-of-box-entity/6645/2 "2018-03-10T21:16:09Z")

</div>

Hello everyone,

Can someone please help me with this? How I can control the orientation of a box entity? I have created bounding boxes around waypoint of my path. But the orientation of each box is facing front. I want it to face the direction of each waypoint. Please help. I’m trying to build a slice of an air-corridor and then try to expand it later along the path to build a 3D shaped corridor.

---

<div class="post-metadata">

**Author:** ![Aasim\_Kamal](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@Aasim\_Kamal](https://community.cesium.com/u/Aasim_Kamal)\
**Post date:** [March 12, 2018, 7:00pm UTC](https://community.cesium.com/t/how-to-control-the-orientation-of-box-entity/6645/3 "2018-03-12T19:00:27Z")

</div>

Can anyone please help me with it? I really need to control the orientation of my boxes in the figure. Thank you very much!

---

<div class="post-metadata">

**Author:** ![hannah](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hannah/32/4509_2.png) [@hannah](https://community.cesium.com/u/hannah)\
**Post date:** [March 12, 2018, 8:59pm UTC](https://community.cesium.com/t/how-to-control-the-orientation-of-box-entity/6645/4 "2018-03-12T20:59:09Z")

</div>

Hello,

Have you seen or Corridor and PolylineVolume geometry types? I think one of these exactly solves your use case:

> **[Cesium Sandcastle](https://sandcastle.cesium.com/?src=Corridor.html&label=Geometries)**
>
> The Cesium Sandcastle provides an interactive environment for testing Cesium code.

> **[Cesium Sandcastle](https://sandcastle.cesium.com/?src=Polyline%20Volume.html&label=Geometries)**
>
> The Cesium Sandcastle provides an interactive environment for testing Cesium code.

But if you do need to orient a box entity, you can do so by setting the ‘orientation’ property. Here’s an example:

var box = viewer.entities.add({  
position: Cesium.Cartesian3.fromDegrees(-114.0, 40.0, 300000.0),  
orientation: Cesium.Quaternion.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(Math.PI, 0, 0)),  
box : {  
dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),  
material : Cesium.Color.BLUE  
}  
});

``

Best,

Hannah

---

<div class="post-metadata">

**Author:** ![Aasim\_Kamal](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@Aasim\_Kamal](https://community.cesium.com/u/Aasim_Kamal)\
**Post date:** [March 14, 2018, 10:11pm UTC](https://community.cesium.com/t/how-to-control-the-orientation-of-box-entity/6645/5 "2018-03-14T22:11:54Z")

</div>

Thank you so much Hannah! I could have used Corridor geometry types, however, the problem is that I have to build these bounding boxes and then interpolate the geometry. It’s the requirement of my project.
