• 已知两条线段端点,判断是否相交及交点


    Function TriAreaSize(ByVal ax As Double, ByVal ay As Double, ByVal bx As Double, ByVal by As Double, ByVal cx As Double, ByVal cy As Double) As Double

    TriAreaSize = ((ax - cx) * (by - cy) - (ay - cy) * (bx - cx)) * 0.5

    End Function

    Function GetIfTwoLineIntr(ByVal ax As Double, ByVal ay As Double, ByVal bx As Double, ByVal by As Double, _
    ByVal cx As Double, ByVal cy As Double, ByVal dx As Double, ByVal dy As Double, _
    ByRef IntrX As Double, ByRef IntrY As Double) As Boolean

    Dim area_abc, area_abd As Double
    Dim area_cda, area_cdb As Double
    Dim t, ddx, ddy As Double

    GetIfTwoLineIntr = True

    area_abc = Nis_Fun.TriAreaSize(ax, ay, bx, by, cx, cy)
    area_abd = Nis_Fun.TriAreaSize(ax, ay, bx, by, dx, dy)

    If area_abc * area_abd < 0 Then Exit Function

    area_cda = Nis_Fun.TriAreaSize(cx, cy, dx, dy, ax, ay)
    area_cdb = Nis_Fun.TriAreaSize(cx, cy, dx, dy, bx, by)

    If area_cda * area_cdb < 0 Then Exit Function

    GetIfTwoLineIntr = False

    t = area_cda / (area_abd - area_abc)
    ddx = t * (bx - ax)
    ddy = t * (by - ay)

    IntrX = ax + ddx
    IntrY = ay + ddy

    End Function

  • 相关阅读:
    Method of Four Russians 学习笔记
    一道不知道哪里来的数论题
    ICPC2021银川 游记
    决策单调性优化dp学习笔记
    浅谈如何优美地实现线段树?
    2021 EC Final 2020 题解
    5.5 SYSU校内训练
    5.4 SYSU校内训练
    存储相关招聘信息-长期
    screen几个使用方法
  • 原文地址:https://www.cnblogs.com/xpvincent/p/7839992.html
Copyright © 2020-2023  润新知