javascript - elements on ellipse edge in d3js -


i try put images oval edge. large extent on poles. have oval:

  var oval = group.append("ellipse")             .attr("cx", this.svgwidth / 2)             .attr("cy", this.svgheight / 2)             .attr("rx", this.rx)             .attr("ry", this.ry)             .style("stroke", "#bcbbb6")             .style("stroke-width", "3px")             .style("fill", "transparent"); 

and have image coordinates:

var imgx = math.cos(that.angle * j) * that.rx - this.model.radius; var imgy = math.sin(that.angle * j) * that.ry - this.model.radius; 

how can arrange them evenly? enter image description here

you cannot add image ellipse tag can set image ellipse background, add picture position mention, create circle set image background of them :

var oval = group.append("ellipse")         .attr("cx", this.svgwidth / 2)         .attr("cy", this.svgheight / 2)         .attr("rx", this.rx)         .attr("ry", this.ry)         .style("stroke", "#bcbbb6")         .style("stroke-width", "3px")         .style("fill", "transparent");  oval.selectall("circle")         .append("circle")         .attr("cx" ,imgx )         .attr("cy",imgy)         .attr("r","8px")         .attr("fill","url(#img)");  var imgx = math.cos(that.angle * j) * that.rx - this.model.radius; var imgy = math.sin(that.angle * j) * that.ry - this.model.radius; 

update1

to real position have change polar angle cartesian.

var imgx = math.cos((that.angle)*math.pi * j/180.0) * that.rx - this.model.radius; var imgy = math.sin((that.angle)*math.pi * j/180.0) * that.ry - this.model.radius;   

update 2

i create sample asked, hope you.

    var width = 600, height = 600;     var rx = 200, ry = 150;     var circlenumbers = 20;      var svg = d3.select("body").append("svg")         .attr("width", width).attr("height", height)         .attr("transform", "translate(0,150)");      var ellipse = svg.append("ellipse")         .attr("cx", width / 2)         .attr("cy", height / 2)         .attr("rx", rx)         .attr("ry", ry)         .style("stroke", "#bcbbb6")         .style("stroke-width", "3px")         .style("fill", "transparent");     var degree = 360 / circlenumbers;      (var = 0; < circlenumbers; i++) {         var circleposition = polartocartesian(width / 2, height / 2, rx, ry, * degree);         svg.append("circle")             .attr("cx", circleposition.x)             .attr("cy", circleposition.y)             .attr("r", "8px")             .attr("fill", "red");     } 

this function return position on ellipse specific degree:

     function polartocartesian(centerx, centery, radiusx, radiusy, angleindegrees) {          var angleinradians = (angleindegrees* math.pi / 180.0);           return {             x: centerx + (radiusx * math.cos(angleinradians)),             y: centery + (radiusy * math.sin(angleinradians))         };     } 

complete jsfiddle here.

update 3

i made changes polartocartesian() function , make ellipse better.i changed begin angle -90 , it's seem better.

        function polartocartesian(centerx, centery, radiusx, radiusy, angleindegrees) {          var angleinradians = ((angleindegrees-90)* math.pi / 180.0);           return {             x: centerx + (radiusx * math.cos(angleinradians)),             y: centery + (radiusy * math.sin(angleinradians))         };     } 

complete jsfiddle here.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -