Math 如何基于点计算圆的起点和终点

Math 如何基于点计算圆的起点和终点,math,Math,我想斜切矩形的边,为了这样做,我想画一个从起点到终点的圆,如图所示 在画一个完整的圆圈时,我就是这样做的 float angle = 2.0f * M_PI * i / iSegments; // vertex data float x, y, z ,tx,ty ,tz; x = cos(angle) * 50.0; y = sin(angle) * 50.0; z = 0.0; 在给定的情况下,我们如何计算圆的顶点?圆的中心在x和y方向上距离角点半径。在您的示例中,半径为30。要绘制90

我想斜切矩形的边,为了这样做,我想画一个从起点到终点的圆,如图所示

在画一个完整的圆圈时,我就是这样做的

float angle = 2.0f * M_PI * i / iSegments;
// vertex data
float x, y, z ,tx,ty ,tz;
x = cos(angle)  * 50.0;
y = sin(angle)  * 50.0;
z = 0.0;

在给定的情况下,我们如何计算圆的顶点?

圆的中心在x和y方向上距离角点
半径。在您的示例中,
半径为30。要绘制90°(π/2弧度)的圆弧,可以从第一个角度开始,将π/2划分为任意多个线段。第一个角度取决于矩形的哪个角被处理。在右上角的示例中,起始角度为0°

下面是一些代码来说明这个概念:

// draw a circular bevel to a rectangle, given are
//   p_x, p_y: the coordinates of the corner, e.g. 50, 50
//   rad: the radius of the bevel, e.g. 30
//   dir_x: the direction to indicate whether the center of 
//     the circle lies lef (dir_y=-1) or right (dir_x=+1) of the corner
//   dir_y: the direction to indicate whether the center of 
//     the circle lies lower (dir_y=-1) or higher (dir_y=+1) than the corner

void draw_circular_bevel (float p_x, float p_y, float rad, int dir_x, int dir_y)
{
  float c_x, c_y;   // the center of the circle
  float start_angle; // the angle where to start the arc
  c_x = p_x + rad * dir_x;
  c_y = p_y + rad * dir_y;
  if (dir_x == 1 and dir_y == 1) 
    start_angle = 0.0;
  else if (dir_x == 1 and dir_y == -1) 
    start_angle = - M_PI * 0.5f;
  else if (dir_x == -1 and dir_y == 1) 
    start_angle = M_PI * 0.5f;
  else if (dir_x == -1 and dir_y == -1) 
    start_angle = - 2.0f * M_PI;
  for (int i=0; i <= iSegments; ++i) {
    float x, y;
    float angle = start_angle + 0.5f * M_PI * i / (float)iSegments;
    x = c_x + cos(angle) * rad;
    y = c_y + sin(angle) * rad;
    // here call code to draw a point or a segment at position x,y
  }
}
//在给定的条件下,将圆形斜面绘制为矩形
//p_x,p_y:角点的坐标,例如50,50
//弧度:斜面的半径,例如30
//dir_x:指示
//圆位于拐角的左(dir_y=-1)或右(dir_x=+1)
//dir__y:用于指示
//圆比角低(dir_y=-1)或高(dir_y=+1)
空心绘制圆形倒角(浮点p_x、浮点p_y、浮点rad、int dir_x、int dir_y)
{
浮点数c_x,c_y;//圆心
float start_angle;//开始圆弧的角度
c_x=p_x+rad*dir_x;
c_y=p_y+rad*diru y;
if(dir_x==1和dir_y==1)
起始角=0.0;
else if(dir_x==1和dir_y==1)
起始角=-M_PI*0.5f;
else if(dir_x==1和dir_y==1)
起始角=M_PI*0.5f;
else if(dir_x==-1和dir_y=-1)
起始角=-2.0f*M\uπ;

对于(int i=0;i当圆的中心应为矩形中心时,圆将无法与其他边平滑对齐。您确定不需要精确的四分之一圆吗?@BDL倒角将根据倒角大小而变化,因此圆可以是任意大小。因此您的图像可能如下所示:。开始和结束点t计算则更为简单,因为它们是圆心+[0,半径]和圆心+[radius,0]。@BDL X和Y斜角距离将始终保持不变,因此应该是圆的四分之一。@shomit BDL图片显示圆心位于(70,70),圆半径为(100-70=30)因此,圆的四分之一完全适合于直角,并平滑共轭。圆弧上的点是
cx+r*cos(角度),cy+r*sin(角度)
,其中cx,cy是中心坐标