orientation problem in dynamic visualization with CZML

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

I met a problem when I use compositeProperty for orientation. The goal is to display vehicles driving according to track data, which has already converted to CZML file. when the vehicles sometimes stop before traffic light, the orientation of vehicles becomes a problem. With Omar’s help, I use the compositeProperty for orientation, and rewrote CZML file with position intervals(moving interval, stop interval ). The scene in my demo is that a vehicle drives from 00:00 to 00:40, stops until 01:26, and then drives again to end. In code I tried to get the orientation of last time point in a moving interval and assign it as the orientation of next stopping interval. But when running to the stop interval, the vehicle turns to the default orientation again. I checked the orientation value of VelocityOrientationProperty and found it has no value at the stop time point: movingOri.getValue(vehicleInterval.stop) undefined, then I tried to assign the orientation of last second time point to the stop interval, but the vehicle shakes a while and suddenly turns 180deg. I don’t know where the problem is, is the problem of time interval definition in CZML again? I uploaded my CZML file here and below is the link of code in Sandcastle. Could anyone help me to get through this? Many thanks in advance!

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

code shared in sandcastle:

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

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

Cesium 1.57, Windows system, chrome/ firefox browser.

CZMLfromSUMO_singleVeh.czml (6.43 KB)

It looks like the problem is that you have only one stopOrientation property, but you need the vehicle to have multiple different “stop orientations” depending on what the time is. Take a look at this line:

// use the orientation of second last time point of last moving interval

var lastSecondTimeSpot = new Cesium.JulianDate();

Cesium.JulianDate.addSeconds(vehicleInterval.stop, -1, lastSecondTimeSpot);

stopOri.setValue(movingOri.getValue(lastSecondTimeSpot));

``

If you console.log the value of stopOri here, you’ll notice that line of code gets executed twice. But since stopOri is a constant property, each time you set its value, it will overwrite what was before. I manually added a check to make it only execute once, and the vehicle behaves as expected:

// define this variable somewhere at the top of the code
var doneOnce = false;
// …
// Then back to the snippet above, it’s replaced with:
if (!doneOnce){

doneOnce = true;

stopOri.setValue(movingOri.getValue(lastSecondTimeSpot));

console.log(movingOri.getValue(lastSecondTimeSpot));

}

``

Here’s a Sandcastle where you can see this. I embedded your CZML in the code so this should be a standalone code example. Hopefully this makes sense. I think the solution here would be to create a composite property whose value is a different constant property for different intervals.

Thanks a lot for your help!

I tried your code snippet in sand castle and it didn’t turn around 180deg any more. I will try to create a composite property for stopOri. But there is another thing still looks weird: just before the vehicle stops, it shakes a little bit and then stops, the orientation when it stops seems not the same as the last moving point orientation but a little bit tilted, but actually it is indeed assigned to the orientation value of second last moving point. hope you can understand what I mean. And there is an error in console:’ TypeError: vehicle.position.setInterpolationOptions is not a function’. I really want the vehicle to stop like a normal car in real world, no shaking, no tilted orientation. Is there anyway to do it? Looking forward to your help.

The sandcastle code is here:https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/#c=zVr9b6M4Gv5XfP2lRNshYL7TdnRznWqvd51L1WS6d7MdVS5xE2sAIzCZbVf9388QkgDh5dxZaXUoSoPt9/HL834Zu2uSofAljtA5+vU+QQj9Xn3L6/6IFGLFs/ujyf3Rh/rnyb53TbOc8aTqNnWj1ccWVfOCh0VME9HqCyMefpPdu4k2Eomg2ZpElRw2zOCd4bwz/LlhTKrPl3G70XQntvWlAVyhxEUkWBoxWmqN231hkWVSlzmLKTjJ/dFW5LWhcUJqkTuWFyRiLyxZop9v/o0WRBD0lPEYzT5/mtbCtWSDx5TnTGyo+rWhUpOAH+JAfmyjw0EFRFMergYe8kAgJJngy4ykKxZ+pMuM0ryj7OYyTg6aTFO3Lcu1/cMu29c917Zw0CPVh6SD8LZnQvDYd9TgMQyPAw+Et9XQLRjdtF0I3QxcNXgbhjdMG4R3FLlxQHjsu7D2hqcG78LwnmVB8IaryL0HwzsBqL1hKnLvw/C2gwF4K3AtNfgAhpeOD8Kram8aMD42HQjfVyXfhMMWGz5Ij6/qOyYct2bgQFnH8hxF+k04ck3fBvn3DFV+4NA1PQw5f39C7cWHY9d0AhDf8VXx4eCVic0D8S2siA9Hr2nZoH/anqr+cPiaGIP+aWNV/4Hj1zR8UH/LNRXLFhy/RuCB+luq8HD4Gr4FmherFl04eg0Pg+yYgaJ1MRy9h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xp1XT8by9tDKcF59EiyHeJ/AQ

Kind regards,

Kathy

The error is because it looks like setInterpolationOptions is only available on SamplePositionProperty (see https://cesiumjs.org/Cesium/Build/Documentation/SampledPositionProperty.html?classFilter=SampledP#setInterpolationOptions). You might need to set it in the CZML itself like in this example:

https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=CZML%20Polygon%20-%20Interpolating%20References.html

This reference page may also be helpful: https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/InterpolatableProperty

Or just set all your positions outside of CZML directly with the Entity API.

As for the shake, I do believe this is because the velocity of the truck changes in that last part as it slows down, and since orientation is automatically computed from velocity, we see this difference. I’m not entirely sure if it is getting the right orientation, or if it’s not taking enough samples and this change is actually an error. To make debugging this a little easier, here’s a version with a dynamic arrow representing the truck’s computed velocity. It’s clear here that the velocity is jumping around. This is where the velocity is being computed:

It gets two positions in time and subtracts them. So I’m not entirely sure where the problem might be, but hopefully this gives you some direction to look into.

Hi Omar,

thanks again for your help! For the interpolation, do you mean that I should add interpolation in CZML and delete the ‘setInterpolationOptions’ in App.js? But I saw in Cesium-workshop demo() that interpolation exists in both App.js and CZML file for the drone. In App.js it sets interpolationAlgorithm : Cesium.HermitePolynomialApproximation, and in CZML file it sets “interpolationAlgorithm”:“LAGRANGE”, so I was confused which interpolation algorithm actually works and should set it once or twice.

For the shake, I think maybe there is some problem with the function ‘VelocityOrientationProperty’. I saw the arrows you drew to show the direction of velocity, it was very clear. The CZML file is only track data samples, and from the track samples, we can see the vehicle slows down in front of the light and then stop. I will check the velocity calculating as you suggested to see where the problem is. Thank you once again!

Best wishes,

Kathy