弧经特定方向3点 [英] arc via 3 points in specific direction
问题描述
我被卡在8grade几何问题=(
我需要从特定方向的3点绘制弧线
我们说我有3个vec2点P1,P2,P3;
我已经设法找到弧中心:
I'm stuck at 8grade geometry question =( 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;
},
b $ b
和radius ...
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;
},
但是这种方法不能给我一个方向,b)不必总是包括第三点(显示圆上的相反圆弧)
But this approach does not give me a) direction, b) it does not always include 3rd point (shows opposite arc on the circle)
所以我需要纠正那些角度,使用旋转方向(顺时针,逆时针)和第三角度需要包括在弧中。
这部分给了我stackoverflow在我的头...所有的链接在google成为一个,导致写问题页面。我不能开箱...帮助我,集体心灵))
so I need to correct those angles I have, using rotation direction (clockwise, counterclockwise) and 3rth angle i need to include in arc. This part gave me stackoverflow in my head... all links in google became one, leading to writing question page. I cant get out of the box... Help me, collective mind ))
推荐答案
矢量数据椭圆弧到SVG ...
heh was there too while convert some specific vector data elliptic arcs to SVG ...
几个如果应该做。我看到你的情况如下:
few if should do it. I see your case like this:
尝试此角度校正:
if (a2-a1>+180.0) a2-=360.0;
if (a2-a1<-180.0) a2+=360.0;
if (a3-a2>+180.0) a3-=360.0;
if (a3-a2<-180.0) a3+=360.0;
并且在此之后方便:
if (a2-a1< 0) dir = CW;
if (a2-a1> 0) dir = CCW;
if (a2-a1==0) dir = none;
唯一的问题是当你的弧覆盖整个360度圆或更多...
The only problem is when your arc cover whole 360 degree circle or more ...
- 那么这还不够
如下:
for (i=0,a=a1;i<100;i++,a+=(a3-a1)/99.0) // 100 lines per arc or use GDI arc ...
{
x=C.x + R*cos(a*PI/180.0);
y=C.y + R*sin(a*PI/180.0); // or - R*... if your render device has opposite Y direction
if (!i) ...->Canvas->MoveTo(x,y);
else ...->Canvas->LineTo(x,y);
}
- R = | P1-C | li>
- R = |P1-C|
这篇关于弧经特定方向3点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!