move 3D entity in a direction defined by an angle

397 views
Skip to first unread message

mdi...@gmail.com

unread,
Nov 4, 2015, 5:49:57 AM11/4/15
to cesium-dev
Hello,

I'm new using Cesium and what I want to do is to draw a cone pointing in a certain direction and shift the cone so that one of the edges connect to a pole.

I have managed to draw the cone in the desired location, but I can't find a way to offset the cone to make the tip connect to a pole on the original coordinate.

What I need to do is to offset an object by half his size in a specific angle.

Here is the code I have so far. This function puts the cone pointing in the direction I want but it doesn't move where I want it:

create3DNetwork = function (networkItem) {

var solidLength = 2.0;
var position = networkItem._position._value;
var azimuthRadians = Cesium.Math.toRadians(networkItem.properties.AZIMUTH);
var shift_x = -Math.sin(Cesium.Math.PI - azimuthRadians) * solidLength;
var shift_y = -Math.cos(Cesium.Math.PI - azimuthRadians) * solidLength;

//Transform a point
var transformationMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(position);
var offset = new Cesium.Cartesian3(shift_x, shift_y, 0);
var finalPos = Cesium.Matrix4.multiplyByPoint(transformationMatrix, offset, new Cesium.Cartesian3());

var heading = azimuthRadians;
var pitch = 0.0;
var roll = Cesium.Math.PI_OVER_TWO - Cesium.Math.toRadians(networkItem.properties.TILT);
orientation = Cesium.Transforms.headingPitchRollQuaternion(finalPos, heading, pitch, roll);
$scope.viewer.entities.add({
position: finalPos,
orientation: orientation,
cylinder: {
length: solidLength * 2,
topRadius: 0.0,
bottomRadius: solidLength,
//slices: 4, //Add this parameter if you want to change the shape of the cilinder (e.g. to a pyramid)
material: Cesium.Color.fromCssColorString("#7A0304").withAlpha(0.5) //RBG: 122,3,4
}
});
}

Thank you so much
Migue Dias

mdi...@gmail.com

unread,
Nov 5, 2015, 12:30:56 PM11/5/15
to cesium-dev, mdi...@gmail.com
I found a solution. I'm not sure it is the best one using Cesium functionalities, but it works.

I created this function to shift the point of insertion of the cone:

// shift a coordinate from a point to a certain distance and direction
$scope.shiftPoint = function (startPoint, bearing, distance, earthRadius) {

var verticalAngle = distance / earthRadius;
var endLatitude = Math.asin(Math.sin(startPoint.latitude) * Math.cos(verticalAngle) +
Math.cos(startPoint.latitude) * Math.sin(verticalAngle) * Math.cos(bearing));
var endLongitude = startPoint.longitude + Math.atan2(Math.sin(bearing) * Math.sin(verticalAngle) * Math.cos(startPoint.latitude),
Math.cos(verticalAngle) - Math.sin(startPoint.latitude) * Math.sin(endLatitude));
return Cesium.Cartesian3.fromRadians(endLongitude, endLatitude, startPoint.height);
Reply all
Reply to author
Forward
0 new messages