Skip to content

Instantly share code, notes, and snippets.

@kikitte
Last active July 27, 2023 14:35
Show Gist options
  • Save kikitte/c07fd49b3f1a2cdd173d1cd83c8f856e to your computer and use it in GitHub Desktop.
Save kikitte/c07fd49b3f1a2cdd173d1cd83c8f856e to your computer and use it in GitHub Desktop.
常用计算几何算法
整理一下工作学习中用到的计算几何算法,大多使用JavaScript实现。
@kikitte
Copy link
Author

kikitte commented Jan 17, 2022

/**
 * 将第三个点投影到由两个点所在的直线上
 * @param {Point} segP0
 * @param {Point} segP1
 * @param {Point} anotherPt
 */
function projectPointOnLine(segP0, segP1, anotherPt) {
  /**
   * x轴方向单位步进带来的y轴方向单位步进。
   * 当segP1[0] - segP0[0]为0时,JavaScript的计算结果为Infinity
   */
  var k = (segP1[1] - segP0[1]) / (segP1[0] - segP0[0])

  /**
   * 处理线段水平和竖直的情况
   */
  if (k === 0) {
    return [anotherPt[0], segP0[1]]
  } else if (!isFinite(k)) {
    return [segP0[0], anotherPt[1]]
  }

  /**
   * 垂线斜率
   */
  var prepK = -1 / k

  var n = anotherPt[1] - prepK * anotherPt[0]
  var m = segP0[1] - k * segP0[0]

  var ix = (n - m) / (k - prepK)
  var iy = k * ix + m

  return [ix, iy]
}

QQ图片20220117232532

@kikitte
Copy link
Author

kikitte commented Apr 4, 2022

@kikitte
Copy link
Author

kikitte commented Apr 10, 2022

求平面方程和直线交点
IMG_20220410_081059

@kikitte
Copy link
Author

kikitte commented Apr 10, 2022

原坐标系下 三个两两垂直的向量构成新坐标系,求从原坐标系到新坐标系的空间变换矩阵
IMG_20220526_224759

平面直角坐标系下情形:
IMG_20220819_224052

@kikitte
Copy link
Author

kikitte commented Apr 28, 2022

坡面法向量在XOZ平面和YOZ平面上的投影线的坡度大小,可能实际用处比较小。
IMG_20220501_151307

@kikitte
Copy link
Author

kikitte commented Sep 13, 2022

1663055740107

@kikitte
Copy link
Author

kikitte commented Oct 29, 2022

空间直角坐标系中点的平移、旋转、缩放后坐标计算

1667037122635

1667037122632
1667037122629
1667037122627

@kikitte
Copy link
Author

kikitte commented Nov 17, 2022

求经纬坐标系上某点沿经线、纬线方向前进单位距离所导致的经纬度变化量:
1668692398189

@kikitte
Copy link
Author

kikitte commented Jul 27, 2023

平面直角坐标系上点向左向右旋转90度以及以y=x的对称点:
1690468443172

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment