Math 在圆上画线

Math 在圆上画线,math,vector,geometry,java-me,Math,Vector,Geometry,Java Me,在a和B之间的中心有一条线a-B和C。它形成一个如图所示的圆。如果我们假设a-B线是圆的直径,那么C是它的中心。我的问题是,我不知道如何再画三条线(蓝色),每一条线与AC或AB成45度角。不,这不是作业,这是渲染中复杂几何体的一部分 在原点用C平移A(即A-C),顺时针旋转45°,然后向后平移。再重复三次。在原点用C平移A(即A-C),顺时针旋转45°,然后向后平移。再重复三次。如果您想找到蓝线的坐标,您可能会找到一些关于变换(旋转)的有用信息: 您需要旋转例如矢量AC,然后您可以找到蓝线端点

在a和B之间的中心有一条线a-B和C。它形成一个如图所示的圆。如果我们假设a-B线是圆的直径,那么C是它的中心。我的问题是,我不知道如何再画三条线(蓝色),每一条线与AC或AB成45度角。不,这不是作业,这是渲染中复杂几何体的一部分


在原点用C平移A(即A-C),顺时针旋转45°,然后向后平移。再重复三次。

在原点用C平移A(即A-C),顺时针旋转45°,然后向后平移。再重复三次。

如果您想找到蓝线的坐标,您可能会找到一些关于变换(旋转)的有用信息:


您需要旋转例如矢量AC,然后您可以找到蓝线端点的坐标。

如果您想找到蓝线的坐标,您可能会找到一些关于变换(旋转)的有用信息:


例如,你需要旋转矢量AC,然后你可以找到蓝线端点的坐标。

如果我这样做的话,我会使用(如果你已经很清楚它们是什么,请原谅包含链接)作为一种简单的方法来计算你需要的圆周上点的坐标。然后从圆的中心画线。

如果我这样做的话,我会用(如果你已经很清楚它们是什么,很抱歉包含链接)作为一种简单的方法来计算你需要的圆周上点的坐标。然后从圆的中心向那里画线。

从开始并添加一个带有代码的按钮:

private void btnCircleLined_Click(object sender, System.EventArgs e)
        {
            Graphics graph = Graphics.FromImage(DrawArea);
            int x = 100, y = 100, diameter = 50;

            myPen.Color = Color.Green;
            myPen.Width = 10;

            graph.DrawEllipse(myPen, x, y, diameter, diameter);
            myPen.Color = Color.Red;
            double radian = 45 * Math.PI / 180;
            int xOffSet = (int)(Math.Cos(radian) * diameter / 2);
            int yOffSet = (int)(Math.Sin(radian) * diameter / 2);
            graph.DrawLine(myPen, x, y + yOffSet + myPen.Width + diameter / 2, x + xOffSet + myPen.Width + diameter / 2, y);
            graph.DrawLine(myPen, x, y, x + xOffSet + myPen.Width + diameter / 2, y + yOffSet + myPen.Width + diameter / 2);
            graph.Dispose();
            this.Invalidate();
        }
编辑:无法看到您的图片,因此我错误地插入了您的问题,但这应该可以让您开始了。

开始并添加一个带有代码的按钮:

private void btnCircleLined_Click(object sender, System.EventArgs e)
        {
            Graphics graph = Graphics.FromImage(DrawArea);
            int x = 100, y = 100, diameter = 50;

            myPen.Color = Color.Green;
            myPen.Width = 10;

            graph.DrawEllipse(myPen, x, y, diameter, diameter);
            myPen.Color = Color.Red;
            double radian = 45 * Math.PI / 180;
            int xOffSet = (int)(Math.Cos(radian) * diameter / 2);
            int yOffSet = (int)(Math.Sin(radian) * diameter / 2);
            graph.DrawLine(myPen, x, y + yOffSet + myPen.Width + diameter / 2, x + xOffSet + myPen.Width + diameter / 2, y);
            graph.DrawLine(myPen, x, y, x + xOffSet + myPen.Width + diameter / 2, y + yOffSet + myPen.Width + diameter / 2);
            graph.Dispose();
            this.Invalidate();
        }

编辑:无法看到您的图片,因此我错误地插入了您的问题,但这应该可以让您开始了。

有几种方法可以解决此问题,其中之一是找到直线的角度,然后将其添加45度几次。这里有一个例子,它是用Python编写的,但是翻译数学应该很容易(我尝试过用一种简单的方式编写Python)

以下是几行的输出:

主要功能是计算点,剩下的只是给它一个和一个与圆相交的点,并绘制出图

from math import atan2, sin, cos, sqrt, pi
from matplotlib import pyplot

def calc_points(A, B, C):
    dx = C[0]-A[0]
    dy = C[1]-A[1]
    line_angle = atan2(dy, dx)
    radius = sqrt(dy*dy + dx*dx)
    new_points = []
    # now go around the circle and find the points
    for i in range(3):
        angle = line_angle + (i+1)*45*(pi/180)  # new angle in radians
        x = radius*cos(angle) + C[0]
        y = radius*sin(angle) + C[1]
        new_points.append([x, y])
    return new_points

# test this with some reasonable values
pyplot.figure()
for i, a in enumerate((-20, 20, 190)):
    radius = 5
    C = [2, 2]
    # find an A and B on the circle and plot them
    angle = a*(pi/180)
    A = [radius*cos(pi+angle)+C[0], radius*sin(pi+angle)+C[1]]
    B = [radius*cos(angle)+C[0], radius*sin(angle)+C[1]]
    pyplot.subplot(1,3,i+1)
    pyplot.plot([A[0], C[0]], [A[1], C[1]], 'r')
    pyplot.plot([B[0], C[0]], [B[1], C[1]], 'r')
    # now run these through the calc_points function and the new lines
    new_points = calc_points(A, B, C)
    for np in new_points:
        pyplot.plot([np[0], C[0]], [np[1], C[1]], 'b')
    pyplot.xlim(-8, 8)
    pyplot.ylim(-8, 8)
    for x, X in (("A", A), ("B", B), ("C", C)):
        pyplot.text(X[0], X[1], x)

pyplot.show()

有几种方法可以解决这个问题,其中一种方法是找到直线的角度,然后将其加45度几次。这里有一个例子,它是用Python编写的,但是翻译数学应该很容易(我尝试过用一种简单的方式编写Python)

以下是几行的输出:

主要功能是计算点,剩下的只是给它一个和一个与圆相交的点,并绘制出图

from math import atan2, sin, cos, sqrt, pi
from matplotlib import pyplot

def calc_points(A, B, C):
    dx = C[0]-A[0]
    dy = C[1]-A[1]
    line_angle = atan2(dy, dx)
    radius = sqrt(dy*dy + dx*dx)
    new_points = []
    # now go around the circle and find the points
    for i in range(3):
        angle = line_angle + (i+1)*45*(pi/180)  # new angle in radians
        x = radius*cos(angle) + C[0]
        y = radius*sin(angle) + C[1]
        new_points.append([x, y])
    return new_points

# test this with some reasonable values
pyplot.figure()
for i, a in enumerate((-20, 20, 190)):
    radius = 5
    C = [2, 2]
    # find an A and B on the circle and plot them
    angle = a*(pi/180)
    A = [radius*cos(pi+angle)+C[0], radius*sin(pi+angle)+C[1]]
    B = [radius*cos(angle)+C[0], radius*sin(angle)+C[1]]
    pyplot.subplot(1,3,i+1)
    pyplot.plot([A[0], C[0]], [A[1], C[1]], 'r')
    pyplot.plot([B[0], C[0]], [B[1], C[1]], 'r')
    # now run these through the calc_points function and the new lines
    new_points = calc_points(A, B, C)
    for np in new_points:
        pyplot.plot([np[0], C[0]], [np[1], C[1]], 'b')
    pyplot.xlim(-8, 8)
    pyplot.ylim(-8, 8)
    for x, X in (("A", A), ("B", B), ("C", C)):
        pyplot.text(X[0], X[1], x)

pyplot.show()

在这种情况下,“画”是什么意思?你想自己绘制这些线条上的每一个点,还是只想找出端点,这样你就可以调用操作系统的线条绘制功能?我只需要知道三点,我可以调用api来绘制线条。在这种情况下,“绘制”是什么意思?你想自己绘制这些线条上的每一个点,还是只想计算出终点,这样你就可以调用操作系统的线条绘制函数?我只需要知道三点,我可以调用api来绘制一条线条。很有趣。我不知道C#在J2ME上运行。好吧,不管怎样。从另一个X分量中添加或减去一个X分量,并对其他分量执行相同的操作。所以A'x=Ax-Cx和A'y=Ay-Cy.标记C#是我的错误,我修正了它。你听起来很怪,我一点也不懂你在说什么。你能给我解释一下吗?一个点有两个分量,X和Y。要翻译你在分量上加或减的点。你听起来像天堂,感觉我够不着它(…我不知道你是如何在不知道X和Y是什么的情况下制作图形的…有趣。我不知道C#在J2ME上运行。好吧,无论如何。从另一个X组件中添加或减去一个X组件,然后对另一个组件执行相同的操作)A'x=Ax-Cx和A'y=Ay-Cy。我把C#标错了,我把它修好了。你听起来太怪了,我一点也不明白你在说什么。你能给我解释一下吗?一个点有两个分量,x和y。要翻译你在分量上加减的那个点。你听起来像天堂,感觉我够不着它(…我不知道你是如何在不知道X和Y是什么的情况下绘制图形的…我想这会给我的问题增加额外的复杂性。真的吗?你确定你已经仔细考虑过了吗?如果你知道什么是“sin”和“cos”以及相关的三角形(在我的学校,那是在7年级或8年级),我打赌你会在一小时内得到这个想法。我想这会给我的问题增加额外的复杂性。真的吗?你确定你已经仔细考虑过了吗?如果你知道什么是“罪”和“因”以及相关的三角形东西(在我的学校是7年级或8年级),我打赌你会在一小时内得到这个想法