【问题标题】:Find coordinates of isosceles triangle with maximum area bounded by ellipse查找最大面积以椭圆为界的等腰三角形的坐标
【发布时间】:2021-01-13 06:33:54
【问题描述】:

“重定向”这里从数学溢出: https://mathoverflow.net/questions/372704/find-coordinates-of-isosceles-triangle-with-maximum-area-bounded-by-ellipse

我有一个窗口,里面刻有一个椭圆。椭圆的半径是 screen_width / 2 和 screen_height / 2。我想找到适合椭圆而不会溢出的最大等腰三角形的坐标。

三角形尖端的方向是一个枚举参数(即 N、E、S、W)。根据我的阅读,没有唯一的解决方案,但最大面积是一个简单的公式,并且有一种方法可以找到解决问题的三角形。然而,这种方式只是暗示,可能涉及使用线性代数将日食和等腰三角形归一化为单位圆和等边三角形,但网上似乎没有这样的公式。

【问题讨论】:

  • 假设你知道半个椭圆的公式。您可以向下迭代计算直角三角形面积的轴,以搜索最大面积。您可能需要在最大迭代时继续细分单位以获得更精确的坐标。

标签: graphics pygame geometry ellipse


【解决方案1】:

基于 Reblochon Masque 的笔记

def inner_rect (self):
        rect = self.outer_rect ()             # bounding box of ellipse
        x, y, w, h = rect
        r = self.child.orientation.radians () # direction of triangle
        pts = inscribe_polygon (3, r)
        pts = graphics_affines (pts)          # from cartesian
        pts = scale_points (pts, rect)        # scale points to ellipse dims
        o, r = bounding_rect (pts)
        xmin, ymin = o
        dx, dy = r
        return (xmin, ymin, dx, dy)

【讨论】:

    【解决方案2】:

    添加到@Reblochon 的答案,这是一个完整的例子。我试过了,为什么不分享呢:)

    import pygame
    from math import sin, cos, pi
    pygame.init()
    
    SW = 600
    SH = 600
    WIN = pygame.display
    D = WIN.set_mode((SW, SH))
    
    radiiX = SW/2
    radiiY = SH/2
    
    def ellipse(center, rx, ry):
        global gotPositions
        angle = 0
        while angle < 6.28:
            angle += 0.0005
    
            pygame.draw.circle(D, (255, 255, 0), (int(center[0]), int(center[1])), 2)
            x = center[0] + sin(angle)* radiiX
            y = center[1] + cos(angle)* radiiY
            D.set_at((int(x), int(y)), (255, 255, 0))
    
    top= (SW/2, 0)  # this one does not change
    bot_left = (SW/2 - SW*cos(pi/6)/2, SH/2 + SH*sin(pi/6)/2) 
    bot_right = (SW/2 + SW*cos(pi/6)/2, SH/2 + SH*sin(pi/6)/2)
    
    points = [top, bot_left, bot_right]
    
    while True:
        D.fill((0, 0, 0))
        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                pygame.quit()
    
        ellipse([radiiX, radiiY], radiiX, radiiY)
        pygame.draw.lines(D, (255, 255, 0), True, points)
        
        pygame.display.flip()
    

    【讨论】:

    • 哈哈,很高兴知道我没有搞砸代数!很适合你尝试一下!
    【解决方案3】:

    一个内接在一个圆中的等边三角形是覆盖圆最大面积的三角形(一些你应该查找的定理)。

    椭圆是一个“压扁”的圆,因此,如果我们用一个内切等边三角形压扁一个圆,只要我们沿着对称线这样做,我们就会得到一个最大面积等腰三角形(两条边被一个共同因子调整大小,第三条边被另一个因子拉伸)。

    角度遵循inscribed angle theoremcomplementary angle theorem

    考虑到你的屏幕宽大于高,三角形3个顶点的坐标如下(在屏幕坐标中,原点在左上角)

    top: (w/2, 0)  # this one does not change
    bot_left = (w/2 - w*cos(pi/6)/2, h/2 + h*sin(pi/6)/2) 
    bot_right = (w/2 + w*cos(pi/6)/2, h/2 + h*sin(pi/6)/2) 
    

    【讨论】:

    • 我什至没想过要乘以 (w,h) 尺寸。这正是我正在寻找的计算。 (我最终得到了内心和外心的功能:P)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 2010-10-07
    相关资源
    最近更新 更多