1
votes

I am trying to find the points which lie within the Sector A of the ARC. I am using D3 to draw the arc on the svg and in a circle where points are plotted. When I move the arc with their start angle or End Angle, the points confined to the ARC changes some property says color or opacity. enter image description here

What I am doing is, I am calculating the angle (P_A) of the all the points (X, Y) from the center(CX,CY) and trying to check that points lies between the angle of the ARC hands i.e startAngle S_A and end Angle E_A. This is the formula I am using

P_A = atan(Y-CY,X-CX)*180.0/PI;

then I am doing the check:

if (P_A < E_A && P_A > S_A)
{
/// SAY Color of Points are changing.
}

Code I have used to genrate the ARC in D3 is given below

    var startAng = 20;
    var arcWidth = 1.5;

    var vis = Space.append("svg")
    var pi = Math.PI;

    var arc = d3.svg.arc()
      .innerRadius(0)
      .outerRadius(radiusC)
      .startAngle(S_A* (pi/180)) //converting from degs to radians
      .endAngle(E_A) //just radians

    vis.attr("width", "400").attr("height", "400") // Added height and width so arc is visible
      .append("path")
      .attr("d", arc)
      .attr("fill", "white")
      .style("stroke","black")
      .style("opacity",0.2)
      .attr("transform", "translate(200,200)");

But it is not working properly.. Nothing is happening as such.

1
Where is your code where you try to modify the attributes of some points?rioV8

1 Answers

2
votes

For angle approach you should use atan2 function and account for cyclic behaviour (when sector includes 180 or 360 border)

Coordinate approach:

make vectors

s = (Cos(startangle), Sin(startangle))
e = (Cos(endangle), Sin(endangle))

for every point make vector

 d = (p.x - center.x, p.y - center.y)

and check that both d lies CCW (counterclockwise) relative to s and d lies CW (clockwise) relative to e using cross product

 if (s.x * d.y - s.y * d.x >= 0)  && (e.x * d.y - e.y * d.x <= 0) 
     then point lies inside sector