Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Cartographic.fromCartesian #3193

Merged
merged 5 commits into from
Nov 12, 2015

Conversation

lilleyse
Copy link
Contributor

For #3177

Added Cartographic.fromCartesian to 3d-tiles. Once this is merged I can also open this pull request into master.

@mramato
Copy link
Contributor

mramato commented Nov 10, 2015

This seems kind of like a weird function to add, since you have to specify the ellipsoid anyway (and the ellipsoid is the thing actually doing the conversion. Why not just call ellipsoid.cartesianToCartographic directly?

@lilleyse
Copy link
Contributor Author

That's what was happening before. It might be useful as a utility function possibly. It would have been nice to let it use a default ellipsoid, but if I try using Ellipsoid.WGS84 I run into cyclical dependencies.

@mramato
Copy link
Contributor

mramato commented Nov 10, 2015

Yes, the circular dependency is exactly why we don't usually have from functions for these types of conversions. Cartesian3 gets around this by duplicating code, but that's because it's a pretty good win for usability. I'm not sure that's the case here.

@pjcozzi
Copy link
Contributor

pjcozzi commented Nov 10, 2015

This is the analog of Cartesian.fromDegrees and is a nice usability improvement for picking, which returns a Cartesian, and then displaying the longitude/latitude/height without an explicit ellipsoid.

That reminds me, we should also update this example: https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Apps/Sandcastle/gallery/Picking.html#L177

To allow the WGS84 default and avoid the dependency, we could duplicate the code or, perhaps better, put it in a @private helper function.

@denverpierce
Copy link
Contributor

+1 for either doing this, or putting in a dummy function or documentation ("looking for .fromCartesian? click here") that points to ellipsoid. cartographic <-> cartesian is a super common operation, but getting a carto from a cart isn't very obvious.

@mramato
Copy link
Contributor

mramato commented Nov 11, 2015

I'm fine with this if we can cleanly factor out a common function (or duplicate a small amount of code) to enable it to default to WGS84

@pjcozzi
Copy link
Contributor

pjcozzi commented Nov 11, 2015

@mramato agreed, I'm confident this can be done cleanly.

@lilleyse
Copy link
Contributor Author

I started to look at this more. It looks like there will be a lot of duplicate code because of scaleToGeodeticSurface, which cartesianToCartographic calls. Maybe there's a way to condense it, I'm just not familiar with the math. Factoring into an outside function seems strange just to make this work...

Could there be some extra file that contains the WGS84 which Cartographic and Cartesian include?

@pjcozzi
Copy link
Contributor

pjcozzi commented Nov 11, 2015

Could there be some extra file that contains the WGS84 which Cartographic and Cartesian include?

I'm not completely following this.

Why not introduce one new file with a @private scaleToGeodeticSurface function that both Ellipsoid and Cartographic include? Then just duplicate the fairly trivial implementation of cartesianToCartographic (with a comment) in Carographic. This code rarely changes so this approach should work well.

@lilleyse
Copy link
Contributor Author

Okay I'll do that, I just wasn't sure if scaleToGeodeticSurface was appropriate as it's own file.

What I meant above was have a really simple file called EllispoidWGS84.js that has a single read-only variable which is the WGS84 ellipsoid. That variable can be initialized from within Ellipsoid. Then Cartographic and Cartesian can include EllispoidWGS84.js, get the WGS84 ellipsoid, and call the functions that they are currently duplicating.

Or you could do the same thing but put the WGS84 var in Cartographic and Cartesian separately, and initialize them in Ellispoid.

@pjcozzi
Copy link
Contributor

pjcozzi commented Nov 11, 2015

Ah, I see now. Interesting, but I think this other approach is more straightforward and avoids potential problems by calling these functions during initialization before that WGS84 variable would be defined.

@lilleyse
Copy link
Contributor Author

This is ready.

@pjcozzi
Copy link
Contributor

pjcozzi commented Nov 12, 2015

Tweaked the picking example. Looks good.

pjcozzi added a commit that referenced this pull request Nov 12, 2015
…phic-from-cartesian

Added Cartographic.fromCartesian
@pjcozzi pjcozzi merged commit b35fafa into 3d-tiles Nov 12, 2015
@pjcozzi pjcozzi deleted the 3d-tiles-cartographic-from-cartesian branch November 12, 2015 13:20
@pjcozzi
Copy link
Contributor

pjcozzi commented Nov 12, 2015

This is also ready for a pull request into master.

@pjcozzi
Copy link
Contributor

pjcozzi commented Nov 12, 2015

I updated Cities.html to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants