In the 3DTiles Feature styling example of Cesium Sandcastle,distance is measured in what way?

268 views
Skip to first unread message

sush

unread,
Jul 30, 2018, 1:25:02 AM7/30/18
to cesium-dev

Can somebody give me a detailed explanation of the below code?

Does it calculate based on earth's curvature also and to what precision?


function colorByDistance() {
tileset.style = new Cesium.Cesium3DTileStyle({
defines : {
distance : "distance(vec2(radians(${longitude}), radians(${latitude})), vec2(-1.291777521, 0.7105706624))"
},
color : {
conditions : [
["${distance} > 0.0012","color('gray')"],
["${distance} > 0.0008", "mix(color('yellow'), color('red'), (${distance} - 0.008) / 0.0004)"],
["${distance} > 0.0004", "mix(color('green'), color('yellow'), (${distance} - 0.0004) / 0.0004)"],
["${distance} < 0.00001", "color('white')"],
["true", "mix(color('blue'), color('green'), ${distance} / 0.0004)"]
]
}
});
}


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

https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=3D%20Tiles%20Feature%20Styling.html&label=3D%20Tiles

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

1.47, win7, chrome

Jane Xu

unread,
Jul 31, 2018, 11:01:41 AM7/31/18
to cesium-dev
Hi! 

The function colorByDistance colors the buildings based on their distance from a specific spot, in this case, the World Trade Center, whose position is denoted by the length 2 vector (-1.291777521, 0.7105706624). The first value is the longitude in radians and the second value is the latitude in radians. There is no height, so that point would be on the ground of the earth.

Regarding your question of whether the distance takes into consideration the curvature of the earth, it does not seem to be according to the documentation. The distance function computes vector math and just calculates length(u - v) where u and v are the vectors. 

Thus, for every building in this set of 3D Tiles, this function first calculates the vector distance between the (lon, lat) of the building with the target position (-1.291777521, 0.7105706624). It then colors based on the result of this calculation. 

sushmapriy...@gmail.com

unread,
Aug 9, 2018, 2:38:38 AM8/9/18
to cesium-dev
thanks Jane.

so the result is in terms of what?
meters/kilometers?

sushmapriy...@gmail.com

unread,
Aug 9, 2018, 3:14:09 AM8/9/18
to cesium-dev

> so the result is in terms of what?
> meters/kilometers?
and the conditions are taken in terms of distance, that is from where is the starting point taken while coloring?

Jane Xu

unread,
Aug 9, 2018, 9:47:56 AM8/9/18
to cesium-dev
Since the vectors are both in radians, the distance calculated would also have units in radians, not kilometers or meters. 

And the conditions do depend on the distance that is evaluated for every building. Every building thus gets colored by how far they are from the World Trade Center.
Reply all
Reply to author
Forward
0 new messages