Graphics 求最大面积为椭圆的等腰三角形的坐标

Graphics 求最大面积为椭圆的等腰三角形的坐标,graphics,pygame,geometry,ellipse,Graphics,Pygame,Geometry,Ellipse,从数学溢出“重定向”到此处: 我有一扇窗户,里面刻着一个椭圆。椭圆半径为屏幕宽度/2和屏幕高度/2。我想找到最大等腰三角形的坐标,它将适合椭圆而不会溢出 三角形尖端的方向是枚举参数(即N、e、s、W)。从我所读到的,没有唯一的解决方案,但最大面积是一个简单的公式,有一种方法可以找到一个三角形来解决这个问题。然而,这种方法仅仅是暗示,可能涉及到使用线性代数将日食和等腰三角形规范化为单位圆和等边三角形,但在线上似乎不存在这样的公式。一个圆内接的等边三角形就是覆盖圆的最大面积的三角形(一些你应该查的

从数学溢出“重定向”到此处:

我有一扇窗户,里面刻着一个椭圆。椭圆半径为屏幕宽度/2和屏幕高度/2。我想找到最大等腰三角形的坐标,它将适合椭圆而不会溢出


三角形尖端的方向是枚举参数(即N、e、s、W)。从我所读到的,没有唯一的解决方案,但最大面积是一个简单的公式,有一种方法可以找到一个三角形来解决这个问题。然而,这种方法仅仅是暗示,可能涉及到使用线性代数将日食和等腰三角形规范化为单位圆和等边三角形,但在线上似乎不存在这样的公式。一个圆内接的等边三角形就是覆盖圆的最大面积的三角形(一些你应该查的定理)

椭圆是一个“挤压”的圆,因此,如果我们挤压一个带有内接等边三角形的圆,只要我们沿着对称线挤压,我们最终会得到一个最大面积等腰三角形(两边按公因数调整大小,第三边按另一因数拉伸)

角度遵循和

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


除了@Reblochon的答案,这里有一个完整的例子。我尝试过,为什么不分享一下呢:)

导入pygame
从数学输入sin,cos,pi
pygame.init()
SW=600
SH=600
WIN=pygame.display
D=赢。设置_模式((SW,SH))
半径=SW/2
半径=SH/2
def椭圆(中心、rx、ry):
全球职位
角度=0
当角度<6.28时:
角度+=0.0005
pygame.draw.circle(D,(255,255,0),(int(center[0]),int(center[1])),2)
x=中心[0]+sin(角度)*半径
y=中心[1]+cos(角度)*半径
D.将_设置为((int(x),int(y)),(255,255,0))
top=(SW/2,0)#此项不变
bot_left=(西南/2-西南*科斯群岛(pi/6)/2,上海/2+上海*辛群岛(pi/6)/2)
机器人右=(SW/2+SW*cos(pi/6)/2,SH/2+SH*sin(pi/6)/2)
点数=[顶部,底部左,底部右]
尽管如此:
D.填充((0,0,0))
events=pygame.event.get()
对于事件中的事件:
如果event.type==pygame.QUIT:
pygame.quit()
椭圆([半径,半径],半径,半径)
pygame.draw.lines(D,(255,255,0),真,点)
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)

假设你知道半个椭圆的公式。可以沿轴向下迭代,计算直角三角形的面积,搜索最大面积。你可能需要在最大迭代时继续细分单位,以获得更精确的坐标。哈哈,很高兴知道我没有把代数搞砸!你尝试一下真是太好了!我甚至没有想到仅仅乘以(w,h)维。这正是我想要的计算结果。(我最终得到的是用于内圆心和外圆心的函数:P)
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()
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)