Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active December 20, 2022 03:46
Show Gist options
  • Save mbostock/a7bdfeb041e850799a8d3dce4d8c50c8 to your computer and use it in GitHub Desktop.
Save mbostock/a7bdfeb041e850799a8d3dce4d8c50c8 to your computer and use it in GitHub Desktop.
Winding Order
license: gpl-3.0
height: 2064
border: no
redirect: https://observablehq.com/@d3/winding-order
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
margin: 0;
}
svg {
font: 10px sans-serif;
border: solid 1px #ccc;
margin-bottom: 10px;
}
</style>
<svg style="position:absolute;top:-1000px;">
<defs>
<marker id="arrow" markerWidth="10" markerHeight="10" refX="0" refY="3" orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,6 L9,3 z" fill="#000"></path>
</marker>
</defs>
</svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var A = {type: "Polygon", coordinates: [[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]},
B = {type: "Polygon", coordinates: [A.coordinates[0].slice().reverse()]};
</script>
<script>
var path = d3.geoPath(d3.geoOrthographic().rotate([-20, -20]).precision(0.1));
var svg = d3.select("body").selectAll()
.data([A, B])
.enter().append("svg")
.attr("width", 958)
.attr("height", 500);
svg.append("path")
.attr("fill", "none")
.attr("stroke", "#000")
.attr("d", path(d3.geoGraticule10()));
svg.append("path")
.attr("fill", "red")
.attr("fill-opacity", 0.5)
.attr("d", path);
svg.append("path")
.attr("fill", "none")
.attr("stroke", "#000")
.attr("marker-mid", "url(#arrow)")
.attr("marker-end", "url(#arrow)")
.attr("d", function(d) { return path({type: "LineString", coordinates: d.coordinates[0]}); });
svg.append("path")
.attr("fill", "none")
.attr("stroke", "#000")
.attr("d", path({type: "Sphere"}));
svg.append("text")
.attr("x", 10)
.attr("y", 10)
.attr("dy", "0.71em")
.text(function(d) { return "ring = " + JSON.stringify(d.coordinates[0]); });
svg.append("text")
.attr("x", 10)
.attr("y", 10)
.attr("dy", "2em")
.text(function(d) { return "area = " + d3.geoArea(d); });
</script>
<script>
var path = d3.geoPath(d3.geoIdentity().translate([480 - 50, 250 - 50]).scale(10));
var svg = d3.select("body").selectAll()
.data([A, B])
.enter().append("svg")
.attr("width", 958)
.attr("height", 500);
svg.append("path")
.attr("fill", "red")
.attr("fill-opacity", 0.5)
.attr("d", path);
svg.append("path")
.attr("fill", "none")
.attr("stroke", "#000")
.attr("marker-mid", "url(#arrow)")
.attr("marker-end", "url(#arrow)")
.attr("d", function(d) { return path({type: "LineString", coordinates: d.coordinates[0]}); });
svg.append("text")
.attr("x", 10)
.attr("y", 10)
.attr("dy", "0.71em")
.text(function(d) { return "ring = " + JSON.stringify(d.coordinates[0]); });
svg.append("text")
.attr("x", 10)
.attr("y", 10)
.attr("dy", "2em")
.text(function(d) { return "area = " + path.area(d); });
</script>
@Adamaiao
Copy link

I am looking for reliable person. who leads a healthy lifestyle. I want him to share my interests about gym and spending time actively. And of course I am looking for the man with a good sense of humor!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment