V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
babyname
V2EX  ›  程序员

请教个数学问题,编程相关。

  •  
  •   babyname · 2015-03-20 14:55:19 +08:00 · 4320 次点击
    这是一个创建于 3329 天前的主题,其中的信息可能已经有所发展或是发生改变。
    一个画布上,有6个点(每个10px),这6个点,围绕画布的中心,组成一个圆,每个点距离围绕画布的中心位置 50px,如何计算6个点的每个点x, y位置?谢谢。

    6个点需要平均分布

    34 条回复    2015-03-24 00:33:28 +08:00
    kokutou
        1
    kokutou  
       2015-03-20 15:00:50 +08:00 via Android   ❤️ 1
    360/5=72度
    然后三角函数算三角形另外一边的边长咯。
    babyname
        2
    babyname  
    OP
       2015-03-20 15:03:34 +08:00
    @kokutou 谢谢,不过不懂三角函数哎。
    b821025551b
        3
    b821025551b  
       2015-03-20 15:05:37 +08:00
    很显然的三角函数,sin(1/2),cos(1/2)神马的
    ieiayaobb
        4
    ieiayaobb  
       2015-03-20 15:09:42 +08:00
    请找初中同学做解析几何
    justfly
        5
    justfly  
       2015-03-20 15:17:42 +08:00
    极坐标转直角坐标 去搜一下吧 好久 都忘了
    b821025551b
        6
    b821025551b  
       2015-03-20 15:21:58 +08:00   ❤️ 2
    我无聊了

    babyname
        7
    babyname  
    OP
       2015-03-20 15:33:28 +08:00
    babyname
        8
    babyname  
    OP
       2015-03-20 15:34:22 +08:00
    ca,按快了。
    我学的已经还给老师了
    @b821025551b 好强悍。
    b821025551b
        9
    b821025551b  
       2015-03-20 15:51:50 +08:00
    @babyname 周五闲着没事,用PS简单画了一下 :)
    mengzhuo
        10
    mengzhuo  
       2015-03-20 15:55:44 +08:00 via iPhone
    0,0 为圆心
    50px为半径
    大部分编程语言的三角函数用弧度制
    要画圆,所以theta 为 0 到 2 * pi
    要六等份即
    pos = [0,1/3pi,2/3pi,pi,4/3pi,5/3pi]

    function (){
    a = []
    for p in pos {
    a.append( (sin(p), cos(p))
    }
    return a
    }

    蹲坑手机上打的 没验证过
    staticor
        11
    staticor  
       2015-03-20 16:55:14 +08:00
    难道是大一作业...
    Freakr
        12
    Freakr  
       2015-03-20 17:14:47 +08:00
    @staticor 感觉像初中,大一不是微积分么。
    b821025551b
        13
    b821025551b  
       2015-03-20 17:17:03 +08:00
    @Freakr 初中可解,貌似大学高数的前几节也有这个(当年高数重修了4次的泪奔了)
    mengzhuo
        14
    mengzhuo  
       2015-03-20 17:46:01 +08:00   ❤️ 1
    wodesuck
        15
    wodesuck  
       2015-03-20 19:51:53 +08:00
    我来一个用复数的
    base = (-1) ** (1 / 3) * 50
    points = [base ** i for i in range(0, 6)]
    复数乘法即是向量旋转
    (py3代码,py2貌似算不了负数的开方
    huxiao1104
        16
    huxiao1104  
       2015-03-20 20:10:58 +08:00
    用极坐标就行了吧
    wodesuck
        17
    wodesuck  
       2015-03-20 20:12:25 +08:00
    @wodesuck 不对...50应该在下面乘的
    base = (-1) ** (1 / 3)
    points = [50 * base ** i for i in range(0, 6)]
    yingluck
        18
    yingluck  
       2015-03-20 20:16:13 +08:00
    什么是均匀分布?应该有无数个解吧
    lololol233
        19
    lololol233  
       2015-03-21 10:25:11 +08:00
    @yingluck 非也
    第一个点的角度为1~60度时 解是不重复的
    这段弧的长度是 60 / 360 * 2 * pi * 50px ~= 52px
    所以就是52个解了
    yingluck
        20
    yingluck  
       2015-03-21 16:10:01 +08:00
    @lololol233
    是的,现在的场景是一个个的像素, 而不是笛卡尔坐标系上一个个的点
    补充一下:
    第一个点在 (0, pi/3] 区间内解才是不重复的。
    把弧拉直算经过的像素,和原始的弧经过的像素数量是不一样的。
    rale
        21
    rale  
       2015-03-21 17:28:07 +08:00
    @b821025551b 你这个图是用啥画的呀
    lololol233
        22
    lololol233  
       2015-03-22 05:41:09 +08:00
    @yingluck
    1. 不明白为什么是pi/3
    2. 我认为可以近似成弧的长度, 如果你知道如何计算二者的误差, 欢迎指教
    lololol233
        23
    lololol233  
       2015-03-22 05:50:59 +08:00
    @lololol233 @yingluck
    我傻逼, 就是pi/3
    b821025551b
        24
    b821025551b  
       2015-03-22 13:54:51 +08:00
    @rale Photoshop
    yingluck
        25
    yingluck  
       2015-03-23 15:08:07 +08:00   ❤️ 1
    大概想了一下,可能还不全面,欢迎讨论

    其实我觉得楼主说的每个点 10 像素是不太恰当的。
    因为在画布上 9个像素 或者 16 个像素 能够拼成正方形。

    围绕画布的中心,那我们假设画布的中心是笛卡尔坐标系的原点。那么六个点每个点到画布中心的距离都是50像素。

    再假设每个像素宽高相同。六个点的每一个点都由 9 个像素组成。

    那么,以原点为圆心,半径为 50 ,画出的圆经过的每一个像素点,都是六边形的六个端点可能的位置。

    在第一象限,用脚本跑了一下,当横坐标是整数的时候,纵坐标的情况是这样的:

    当纵坐标为整数时,可能的中心点有 4 个, 在第一象限有 6 个纵坐标为整数的点
    当纵坐标为非整数时,可能的中心点有 2 个, 在第一象限有 45 个这样的点

    所有不重复的结果有 87 个。

    全部有 348 个可能的点。
    yingluck
        26
    yingluck  
       2015-03-23 15:09:12 +08:00
    the X is 50, the Y is 0.0
    cross (50, 0.0), (49, 0.0)
    the X is 49, the Y is 9.94987437107
    cross (49, 9), (48, 9)
    the X is 48, the Y is 14.0
    cross (48, 14.0), (47, 14.0), (48, 13.0), (47, 13.0)
    the X is 47, the Y is 17.0587221092
    cross (47, 17), (46, 17)
    the X is 46, the Y is 19.5959179423
    cross (46, 19), (45, 19)
    the X is 45, the Y is 21.7944947177
    cross (45, 21), (44, 21)
    the X is 44, the Y is 23.7486841741
    cross (44, 23), (43, 23)
    the X is 43, the Y is 25.5147016443
    cross (43, 25), (42, 25)
    the X is 42, the Y is 27.1293199325
    cross (42, 27), (41, 27)
    the X is 41, the Y is 28.6181760425
    cross (41, 28), (40, 28)
    the X is 40, the Y is 30.0
    cross (40, 30.0), (39, 30.0), (40, 29.0), (39, 29.0)
    the X is 39, the Y is 31.2889756943
    cross (39, 31), (38, 31)
    the X is 38, the Y is 32.4961536185
    cross (38, 32), (37, 32)
    the X is 37, the Y is 33.6303434416
    cross (37, 33), (36, 33)
    the X is 36, the Y is 34.6987031458
    cross (36, 34), (35, 34)
    the X is 35, the Y is 35.7071421427
    cross (35, 35), (34, 35)
    the X is 34, the Y is 36.6606055596
    cross (34, 36), (33, 36)
    the X is 33, the Y is 37.563279942
    cross (33, 37), (32, 37)
    the X is 32, the Y is 38.4187454246
    cross (32, 38), (31, 38)
    the X is 31, the Y is 39.2300904919
    cross (31, 39), (30, 39)
    the X is 30, the Y is 40.0
    cross (30, 40.0), (29, 40.0), (30, 39.0), (29, 39.0)
    the X is 29, the Y is 40.7308237088
    cross (29, 40), (28, 40)
    the X is 28, the Y is 41.4246303544
    cross (28, 41), (27, 41)
    the X is 27, the Y is 42.083250825
    cross (27, 42), (26, 42)
    the X is 26, the Y is 42.7083130081
    cross (26, 42), (25, 42)
    the X is 25, the Y is 43.3012701892
    cross (25, 43), (24, 43)
    the X is 24, the Y is 43.8634243989
    cross (24, 43), (23, 43)
    the X is 23, the Y is 44.3959457608
    cross (23, 44), (22, 44)
    the X is 22, the Y is 44.8998886413
    cross (22, 44), (21, 44)
    the X is 21, the Y is 45.3762052182
    cross (21, 45), (20, 45)
    the X is 20, the Y is 45.8257569496
    cross (20, 45), (19, 45)
    the X is 19, the Y is 46.2493243194
    cross (19, 46), (18, 46)
    the X is 18, the Y is 46.6476151588
    cross (18, 46), (17, 46)
    the X is 17, the Y is 47.021271782
    cross (17, 47), (16, 47)
    the X is 16, the Y is 47.3708771293
    cross (16, 47), (15, 47)
    the X is 15, the Y is 47.6969600708
    cross (15, 47), (14, 47)
    the X is 14, the Y is 48.0
    cross (14, 48.0), (13, 48.0), (14, 47.0), (13, 47.0)
    the X is 13, the Y is 48.2804308183
    cross (13, 48), (12, 48)
    the X is 12, the Y is 48.538644398
    cross (12, 48), (11, 48)
    the X is 11, the Y is 48.774993593
    cross (11, 48), (10, 48)
    the X is 10, the Y is 48.9897948557
    cross (10, 48), (9, 48)
    the X is 9, the Y is 49.1833305094
    cross (9, 49), (8, 49)
    the X is 8, the Y is 49.355850717
    cross (8, 49), (7, 49)
    the X is 7, the Y is 49.5075751779
    cross (7, 49), (6, 49)
    the X is 6, the Y is 49.638694584
    cross (6, 49), (5, 49)
    the X is 5, the Y is 49.7493718553
    cross (5, 49), (4, 49)
    the X is 4, the Y is 49.8397431775
    cross (4, 49), (3, 49)
    the X is 3, the Y is 49.9099188539
    cross (3, 49), (2, 49)
    the X is 2, the Y is 49.9599839872
    cross (2, 49), (1, 49)
    the X is 1, the Y is 49.9899989998
    cross (1, 49), (0, 49)
    the X is 0, the Y is 50.0
    cross (0, 50.0), (0, 49.0)

    the length of PIXLE is 87
    yingluck
        27
    yingluck  
       2015-03-23 15:09:39 +08:00
    @lololol233 看上面
    babyname
        28
    babyname  
    OP
       2015-03-23 15:44:55 +08:00
    @yingluck 可否分享下代码呀,谢谢
    yingluck
        29
    yingluck  
       2015-03-23 15:54:00 +08:00
    babyname
        30
    babyname  
    OP
       2015-03-23 16:04:40 +08:00
    babyname
        31
    babyname  
    OP
       2015-03-23 16:11:06 +08:00
    @mengzhuo 不太懂 python 如果能有其他语言版本就好啦 😄
    Todd_Leo
        32
    Todd_Leo  
       2015-03-23 16:34:31 +08:00
    为什么你的问题跟你的头像这么雷同 XD
    babyname
        33
    babyname  
    OP
       2015-03-23 17:00:24 +08:00
    @Todd_Leo 没错,我要画个头像 :)
    wind3110991
        34
    wind3110991  
       2015-03-24 00:33:28 +08:00
    这个题时要求什么,是反求输入六个点的坐标的话,那么这题答案不止一个哦
    记得三个点确定一个圆,起码除了中心点的话要知道其他两个点的坐标,这题如果要求解,那么应该是输入中心点,加上其他两个点的坐标,求出剩下4个点的坐标
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2546 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 13:02 · PVG 21:02 · LAX 06:02 · JFK 09:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.