How to compute new position from distance and cartesian coordinates

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

I am not able to compute the new position correctly. I have distance and previous cartesian coordinates. On adding, it doesn’t seem to compute new position correctly. I want my path to be midway between red path and yellow path.

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’,

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);

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);

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

var position = Cesium.Cartesian3.fromElements(a[i].x + (0.5d[i]), a[i].y + (0.5d[i]), a[i].z);

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

}

});

}

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(d);

//console.log(a);

//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.

Estimated Corridor Averaging

Start with two sets of overlapping posit tracks and

For each track

   for each posit

         assume the posit is perfectly in the center of the air corridor, compute and store the coordinates of the default sized corridor slice. 

Since the UAVs will fly similar, but not exactly the same paths, when following a corridor the slice coordinates for each UAV path will be different

For a set of UAV paths

find closest UAV 1 and UAV 2 posits and average them to generate a reference path

compute a corridor slice for each posit on the reference path

​interpolate the geometry between each slice to have a closed form 3D shape for the corridor 

Visualize by rendering the 3D shape to your map

The distance between the coordinates in the individual coordinate sets indicates the possible error/uncertainty in the estimation.

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

Cesium-1.42, Windows 10, Mozilla Firefox

Hi everyone, can anyone please suggest how to do this?

Hi Aasim,

you are probably not receiving a reply because you question - as well as your other question - is not a Cesium related, but rather a generic programming/algebra question.

I suggest you start with a good book on Vector Algebra or something like this: https://www.mathsisfun.com/algebra/vectors.html

Hope this helps,

Klaus

Thanks Klaus! I appreciate it!

Hi Klaus,

My another question is indeed Cesium related - Like how I can control the orientation of a box entity. It is indeed Cesium related. Like 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. My detailed question is here: https://groups.google.com/forum/#!topic/cesium-dev/DXQWXVFKtqU

Please help me with this. Thank you!

You can use heading, pitch, and roll to set the orientation of an entity, see this Sandcastle example.

Thanks Gabby for the help!