首页 > 解决方案 > 计算圆上最近的点

问题描述

我正在尝试计算用红色标记的点(在圆和框的角之间创建一条线)

这与返回两个圆之间的 x,y 交点的 JavaScript 函数有类似的问题?

但是,这是针对 2 个圆圈的。

我知道两者的位置,圆半径等,我如何计算到圆上那个角的最近点?

const shapeTop =  this.shape.getAttribute('position').clone()
//I want to apply the position here


const geo = this.button.children[0].getAttribute('geometry')

if(!geo)
  return

const halfWidth = geo.width * 0.5
const halfHeight = geo.height * 0.5

const buttonEdge = {
  x: buttonPos.x + (buttonPos.x > 0 ? - halfWidth :  halfWidth),
  y: buttonPos.y + (buttonPos.y > 0 ? - halfHeight :  halfHeight),
  z: buttonPos.z,
}

圆圈

标签: maththree.js

解决方案


在 three.js 中,您可以像这样计算所需的点:

var vector = new THREE.Vector3(); // or Vector2

vector.copy( corner ).sub( center ).setLength( radius ).add( center );

三.js r.93


推荐阅读