查找最大面积由椭圆界定的等腰三角形的坐标

问题描述

此处从数学溢出中“重定向”: 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)。根据我的阅读,没有唯一的解决方案,但是最大面积是一个简单的公式,并且可以找到一种解决问题的三角形。但是,这种方式只是暗示,可能涉及使用线性代数将日食和等腰三角形归一化为单位圆和等边三角形,但是似乎没有这样的公式在线存在。

解决方法

一个刻在圆上的等边三角形是覆盖圆的最大面积的三角形(您应查找一些定理)。

椭圆是一个“压缩”的圆,因此,如果我们压缩一个带有内切等边三角形的圆,并且沿对称线这样做,则最终得到的最大面积为等腰三角形(两个边的大小由一个公因子调整,第三个边的另一个因数拉伸)。

角度遵循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) 

enter image description here

,

这是@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)),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))
    events = pygame.event.get()
    for event in events:
        if event.type == pygame.QUIT:
            pygame.quit()

    ellipse([radiiX,radiiY],radiiX,radiiY)
    pygame.draw.lines(D,True,points)
    
    pygame.display.flip()
,

基于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)