开发者

Given 3 points, how to construct an arc that passes through them?

Let's say I have 3 consecutive points (P1,P2, P3), how to construct an Arc that passes through all 3 points?

The arc must have the following 3 properties:

  1. Start Radian
  2. End Radian
  3. Center Point

The arc is drawn from Start Radian to End Radian in counter-clockwise manner.

I've tried with the solution here, but it doesn't work, simply because it assumes that P1 must correspond to Start Radian an开发者_高级运维d P3 must correspond to end radian. But the reality is that this is not always valid.


Draw two lines between them, following the order you want the arc to take. Bisect both lines, coming up with their normals. The intersection of the normals is the center of the arc. Draw your arc from one endpoint to the other, with the given center.


I had the same problem. Here is a small snippet in C for that. As you can see there are two possible points for the center point. I hope it helps. Credits to my soon Ignacio:

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void)
{
    float x1,y1; //Punto A
    float x2,y2; //Punto B
    float x3,y3; //Punto medio
    float x,y;
    float z,t; //los otros posibles puntos
    float R; //Distancia

    printf("Introduce  Ax:\n");
    scanf ("%f",&x1);
    printf("Introduce  Ay:\n");
    scanf ("%f",&y1);
    printf("Introduce  Bx:\n");
    scanf ("%f",&x2);
    printf("Introduce  By:\n");
    scanf ("%f",&y2);
    printf("Introduce  Cx:\n");
    scanf ("%f",&x3);
    printf("Introduce  Cy:\n");
    scanf ("%f",&y3);
    printf("Introduce la distancia:\n");
    scanf ("%f",&R);


    x=-((-(x2*x2)+2*x1*x2-(x1*x1))*x3-(x3*y1*y1)+(2*x3*y1*y2)-(x3*y2*y2)+(y2-y1)*sqrt(y2*y2-2*y1*y2+y1*y1+x2*x2-2*x1*x2+x1*x1)*R)/(y2*y2-2*y1*y2+y1*y1+x2*x2-2*x1*x2+x1*x1);
    y=((y2*y2-2*y1*y2+y1*y1+x2*x2-2*x1*x2+x1*x1)*y3+(x2-x1)*sqrt(y2*y2-2*y1*y2+y1*y1+x2*x2-2*x1*x2+x1*x1)*R)/(y2*y2-2*y1*y2+y1*y1+x2*x2-2*x1*x2+x1*x1);
    printf ("x=%f\n",x);
    printf ("y=%f\n",y);

    z=((y2-y1)*sqrt((y2*y2)-2*y1*y2+y1*y1+x2*x2-2*x1*x2+x1*x1)*R+x3*y2*y2-2*x3*y1*y2+x3*y1*y1+(x2*x2-2*x1*x2+x1*x1)*x3)/(y2*y2-2*y1*y2+y1*y1+x2*x2-2*x1*x2+x1*x1);
    t=-((x2-x1)*sqrt(y2*y2-2*y1*y2+y1*y1+x2*x2-2*x1*x2+x1*x1)*R+(-(y2*y2)+2*y1*y2-(y1*y1)-(x2*x2)+2*x1*x2-(x1*x1)*y3))/(y2*y2-2*y1*y2+y1*y1+x2*x2-2*x1*x2+x1*x1);
    printf ("\nx=%f\n",z);
    printf ("y=%f\n",t);
    system("pause");

    return 0;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜