Math 如何计算圆弧的中心点?

Math 如何计算圆弧的中心点?,math,canvas,graphics,drawing,android-canvas,Math,Canvas,Graphics,Drawing,Android Canvas,我有一个CustomPieView,它由几个饼片组成。我必须在每个馅饼部分中间画一些东西。< /P> //内部活动的onCreate方法 创建时的公共void(Bundle savedInstanceState){ } //自定义视图扩展视图 public void setGeometry(int width, int height, int gapleft, int gapright, int gaptop, int gapbottom, int overlayid) { mWidt

我有一个CustomPieView,它由几个饼片组成。我必须在每个馅饼部分中间画一些东西。< /P> //内部活动的onCreate方法

创建时的公共void(Bundle savedInstanceState){

}

//自定义视图扩展视图

public void setGeometry(int width, int height, int gapleft, int gapright, int gaptop, int gapbottom, int overlayid) {

    mWidth = width;
    mHeight = height;
    mGapleft = gapleft;
    mGapright = gapright;
    mGapBottm = gapbottom;
    mGapTop = gaptop;
}
受保护的void onDraw(画布){

canvas.drawColor(Color.DKGRAY);
mBagpaints.setAntiAlias(真);
mBagpaints.setStyle(油漆、样式、填充);
mBagpaints.setColor(0x88FF0000);
mbag油漆设定行程宽度(0.0f);
mLinePaints.setAntiAlias(真);
MLINPAINTS.setColor(颜色:白色);
MLINPAINTS.设定行程宽度(3.0f);
MLINPENTS.setStyle(油漆、样式、笔划);
sLinePaint.setantialas(真);
sLinePaint.setColor(颜色:黑色);
滑动油漆设定行程宽度(3.0f);
sLinePaint.setStyle(油漆、样式、笔划);
RectF mOvals=新的RectF(mGapleft、mGapTop、mWidth-mGapright、mHeight
-mGapBottm);
mStart=START_公司;
piem项目;
对于(int i=0;i
//下面的功能是设置全局变量 cSegX,cSegY到段的中心。不工作

        calculateMidPointOfPieSegment(mSweep);
        canvas.drawPoint(cSegX, cSegY, sLinePaint);
        mStart = mStart + mSweep;
    }
    mState = IS_DRAW;
    callBack.onDrawFinished(null);
}

private float calculateRadius(){
float width = mWidth/2;
float height = mHeight/2;
    if(width < height){
        return width;
    }else{
        return height;
    }
}

private void calculateMidPointOfPieSegment(float sweepAngle){
    cSegX = (float)((calculateRadius()/2)*Math.cos(Math.toRadians(sweepAngle/2))+(mWidth/2));
    cSegY = (float)((calculateRadius()/2)*Math.sin(Math.toRadians(sweepAngle/2))+(mHeight/2));
}
<代码>计算压差点(mSweep); 帆布.拉丝点(cSegX、cSegY、滑面漆); mStart=mStart+mSweep; } mState=IS_DRAW; callBack.onDrawFinished(空); } 专用浮点计算器adius(){ 浮动宽度=mWidth/2; 浮子高度=mHweight/2; if(宽度<高度){ 返回宽度; }否则{ 返回高度; } } 专用空隙计算点压段(浮动扫掠角){ cSegX=(float)((calculateRadius()/2)*Math.cos(Math.toRadians(sweepingangle/2))+(mWidth/2)); cSegY=(float)((calculateRadius()/2)*Math.sin(Math.toRadians(sweepingangle/2))+(mHeight/2)); }
请看下图中的点,它必须位于每个弧的中心。


完成

如果这样可以清除,请告诉我。这是您想要实现的基本逻辑

    //rimPoint = (rX, rY)
    //centerPoint = (cX,cY)
    //theta is the angle of the the midpoint measured anticlockwise from the x axis, 
    //or the average of the two angles making up the slice(measured anticlockwise from 
    //the x axis)
    private void calculateMidPointOfPieSegment(cX,cY, theta)
    {
       float rX = cX + calculateRadius()*(cos(theta))
       float rY = cY + calculateRadius()*(sin(theta))

       cSegX = (rX+cX)/2;
       cCegY = (rY+cY)/2;
    }

如果θ不以弧度为单位,则将其细分为θ*Math.PI/180

你所说的每个弧的中心是什么意思?对于每一个饼状的形状,你想在弯曲的外缘中间放置一个点吗?或者你想让它从饼片的顶端到圆边,从两边等距?我指的是饼片形状的中心点。我有点宿醉了,我不想在源代码中查找您使用的所有变量的来源。但我会帮你解决这个问题。我只想知道你手头有什么数据。你有两个角度或角度的圆,构成了饼片?你能买到吗?另外,从x和y,我假设你在网格上工作,圆心在(0,0)吗?如果不是,它是什么?我正在使用[canvas.drawArc()](float,float,boolean,android.graphics.Paint))方法。为此,我必须通过一个startAngle:start angle(以度为单位),其中圆弧开始扫掠角:扫掠角(以度为单位)顺时针测量“是圆的中心在(0,0)”。不,它位于椭圆的中心(drawArc func的第一个参数),这是在我上面提到的int size=400的行中设置的;集合几何(大小,大小,2,2,2,2,2130837504);你看到我的答案了吗/它解决了你的问题了吗?
        calculateMidPointOfPieSegment(mSweep);
        canvas.drawPoint(cSegX, cSegY, sLinePaint);
        mStart = mStart + mSweep;
    }
    mState = IS_DRAW;
    callBack.onDrawFinished(null);
}

private float calculateRadius(){
float width = mWidth/2;
float height = mHeight/2;
    if(width < height){
        return width;
    }else{
        return height;
    }
}

private void calculateMidPointOfPieSegment(float sweepAngle){
    cSegX = (float)((calculateRadius()/2)*Math.cos(Math.toRadians(sweepAngle/2))+(mWidth/2));
    cSegY = (float)((calculateRadius()/2)*Math.sin(Math.toRadians(sweepAngle/2))+(mHeight/2));
}
    //rimPoint = (rX, rY)
    //centerPoint = (cX,cY)
    //theta is the angle of the the midpoint measured anticlockwise from the x axis, 
    //or the average of the two angles making up the slice(measured anticlockwise from 
    //the x axis)
    private void calculateMidPointOfPieSegment(cX,cY, theta)
    {
       float rX = cX + calculateRadius()*(cos(theta))
       float rY = cY + calculateRadius()*(sin(theta))

       cSegX = (rX+cX)/2;
       cCegY = (rY+cY)/2;
    }