从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);
答案 0 :(得分:0)
该代码似乎适用于正交投影和立体投影。正交扭曲并且不是保形,而立体图是保形的并且不会扭曲(好吧,没有那么多)。