鱼C论坛

 找回密码
 立即注册
查看: 1916|回复: 0

[技术交流] 【数学笔记】2. 计算圆上一点的坐标

[复制链接]
发表于 2023-6-29 15:18:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
参考链接:传送门

首先,确定一个圆需要确定它其中一个点的坐标(左上,左,左下,上,中心,下,右上,右,右下)以及它的半径 radius

于是代码可以这么写:
from math import cos, sin, radians

def getpos(radius, topleft, angle):
    pass

又因为我们需要将 topleft 分开考虑,所以
from math import cos, sin, radians

def getpos(radius, topleft, angle):
    left, top = topleft

说明:radius 表示圆的半径,topleft 表示圆左上角坐标 (x, y),angle 表示以穿过圆中心的横线为基准,旋转了几度(顺时针为正数,逆时针为负数)。

下一步是获取圆心坐标。设圆心坐标为 (x0, y0),那么可以确定:

x0 = left + radius
y0 = top + radius


接下来就可以计算坐标了。非常重要的一点是角度和弧度的区别(传送门),需要用 radians() 或者 degrees() 进行角度 <-> 弧度换算。

最终代码如下:
from math import cos, sin, radians

def getpos(radius, topleft, angle):
    left, top = topleft
    x0, y0 = left + radius, top + radius
    x1 = x0 + radius * cos(radians(angle))
    y1 = y0 + radius * sin(radians(angle))
    return x1, y1

一种更简单的情况是,给定的坐标不是 topleft,而是 center

Code:
from math import cos, sin, radians

def getpos(radius, center, angle):
    x0, y0 = center
    x1 = x0 + radius * cos(radians(angle))
    y1 = y0 + radius * sin(radians(angle))
    return x1, y1

评分

参与人数 1荣誉 +1 收起 理由
琅琊王朝 + 1 鱼C有你更精彩^_^

查看全部评分

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-22 15:36

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表