I need to draw the arc from 3 points in specific direction.
Lets say i have 3 vec2 points P1, P2, P3;
I've been manage to find arc center:
circleCenter: function (b, c, d) {
var temp = Math.pow(c.x, 2) + Math.pow(c.y, 2);
var bc = (Math.pow(b.x, 2) + Math.pow(b.y, 2) - temp) / 2.;
var cd = (temp - Math.pow(d.x, 2) - Math.pow(d.y, 2)) / 2.;
var det = (b.x - c.x) * (c.y - d.y) - (c.x - d.x) * (b.y - c.y);
if (Math.abs(det) < 1e-14)
return false;
var circ = new THREE.Vector2((bc * (c.y - d.y) - cd * (b.y - c.y)) / det,
((b.x - c.x) * cd - (c.x - d.x) * bc) / det
);
return circ;
},
and radius...
var startPoint = P1;
var endPoint = P3;
var centerPoint = P2;
var centerPoint = this.circle(startPoint, centerPoint, endPoint);
var r = Math.sqrt((startPoint.x - centerPoint.x) * (startPoint.x - centerPoint.x) + (startPoint.y - centerPoint.y) * (startPoint.y - centerPoint.y));
third step is finding angles which is the place I've been stuck. I'm calculating angles this way for each of point I have:
angleFromOrigin: function (c, p) {
var x = p.x - c.x;
var y = p.y - c.y;
var theta = (180 / Math.PI * Math.atan2(y, x));
return theta;
},
But this approach does not give me a) direction, b) it does not always include 3rd point (shows opposite arc on the circle)
so I need to correct those angles I have, using rotation direction (clockwise, counterclockwise) and 3rth angle i need to include in arc.