继http://stackoverflow.com/questions/18766430/how-can-i-do-d3-svg-arc-within-a-given-map-projection之后,我有了一个略微修改的版本,我想要在某个方位角、天顶角和给定的开放角度上显示一条圆弧。到目前为止,我的努力如下所示。
如果我在(Az,Ze) 0,90和0,45处创建一条圆弧,这些圆弧就是我期望的位置。但是,如果我想在Ze = 45度的每个Az = 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);发布于 2017-07-14 10:40:09
该代码似乎既适用于正交投影,也适用于立体投影。正交是扭曲的,不是共形的,而立体是共形的,不会扭曲(好吧,没有那么多)。
https://stackoverflow.com/questions/44275636
复制相似问题