javascript - (倒置)立体投影上的 D3 弧未按要求显示

标签 javascript d3.js svg

http://stackoverflow.com/questions/18766430/how-can-i-do-d3-svg-arc-within-a-given-map-projection之后,我有一个稍微修改过的版本,我想在某个方位 Angular 、天顶 Angular 和给定的张 Angular 处显示圆弧。到目前为止我的努力如下。

如果我在 (Az,Ze) 0,90 和 0,45 处创建弧线,则弧线将位于我期望的位置。但是,如果我想要在每个 Az = 45 度(Ze = 45 度)处有一个圆弧,则圆弧往往会偏离投影而不是绕行。

知道这里发生了什么吗? Jsfiddle:http://jsfiddle.net/3p9c4kzo/1/

var width = 600,
height = 600;

var flippedStereographic = function(lam, phi)  {
            var cosl = Math.cos(lam),
            cosp = Math.cos(phi),
            k = 1 / (1 + cosl * cosp);
            return [ k * cosp * Math.sin(lam), -k * Math.sin(phi) ];
};

var projection = d3.geo
.projection(flippedStereographic)
.rotate([0, -90])
.scale(180)
.translate([width / 2, height / 2])
.clipAngle(90)
.precision(.1);

var path = d3.geo.path()
.projection(projection);

var graticule = d3.geo.graticule();

var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);

svg.append("defs").append("path")
.datum({
type: "Sphere"
})
.attr("id", "sphere")
.attr("d", path);

svg.append("use")
.attr("class", "stroke")
.attr("xlink:href", "#sphere");

svg.append("use")
.attr("class", "fill")
.attr("xlink:href", "#sphere");

svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);

function geoArc(center, radius, startAngle, endAngle, steps) {
coordinates = []
for (var i = 0; i <= steps; i++) {
    var curAngle = (startAngle + (endAngle - startAngle) * i / steps);
    coordinates[i] = d3.geo.rotation(center)(d3.geo.rotation([0, 0, 
curAngle])([radius, 0]))
}
return {
    type: "LineString",
    coordinates: coordinates
};
}

svg.append("path")
.datum(geoArc([0,90], 30, 0, 360, 40))
.classed("circle", true)
.attr("d", path);

svg.append("path")
    .datum(geoArc([0,45], 30, 0, 360, 40))
.classed("circle", true)
.attr("d", path);

svg.append("path")
    .datum(geoArc([45,45], 30, 0, 360, 40))
.classed("circle", true)
.attr("d", path);

svg.append("path")
    .datum(geoArc([90,45], 30, 0, 360, 40))
.classed("circle", true)
.attr("d", path);

最佳答案

该代码似乎适用于正交投影和立体投影。正交会扭曲且不共形,而立体投影会共形且不会扭曲(好吧,扭曲程度不大)。

正字法 https://au.mathworks.com/help/map/ortho.html

立体投影 https://au.mathworks.com/help/map/stereo.html

关于javascript - (倒置)立体投影上的 D3 弧未按要求显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44275636/

相关文章:

Javascript 用另一种样式替换一种样式

javascript - 无法理解 d3js 缩放功能

javascript - 如何使用嵌套数组对象访问 d3 json 文件中的值

javascript - 如何使用 javascript 或 jquery 动态添加 SVG 图形?

python - 将 AsciiMath/MathML 转换为 SVG/PNG

javascript - 限制 Sequelize 中的延迟加载关联

javascript - Aurelia - 如何为 ViewCompiler 注册 View 资源?

javascript - 如何在 PHP 中接收 Ajax urlencode

arrays - ng-repeat 完成后触发 D3 重绘

SVG 和 DPI,绝对单位和用户单位 : Inkscape vs. Firefox vs. ImageMagick