确定点是否位于特定的几何区域

确定点是否位于特定的几何区域

本文介绍了确定点是否位于特定的几何区域内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

画一个圆圈。现在将圆圈垂直和水平分成四个区域。走左上角的区域。如果你在它周围画了一个盒子,你会有一个带有圆角的盒子,朝东。



给出该单个左上方框中的X和Y坐标区域,我怎么知道一个点是在圆圈的左边还是在右边?

解决方案

你可以通过实现解决问题:


  • 圆的中心位于方块的东南角

  • 该圆圈包含该点的半径 r 中的所有点



你可以解决这个问题,给定圆的中心点(a,b),并知道具有边 r ...任何给定的点(x,y)在盒子里面也是在圆内的当且仅当:

 ((by)^ 2 +(ax)^ 2)< r ^ 2 

当且仅当此条件为假时,此点位于圆外或恰好位于圆上。

正如Derek E.在评论中建议的那样,在实现此解决方案时,最好比较平方距离以避免sqrt函数的近似值。


Picture a circle. Now divide the circle vertically and horizontally into four regions. Take the top left region. If you drew a box around it, you'd have a box with a rounded corner heading east.

Given an X and Y coordinate in that box of that single top left region, how can I tell whether a point is to the left of the circle's line, or to the right?

解决方案

You can solve the problem by realizing:

  • the center of the circle is the southeast corner of the box
  • the circle contains all points within a radius r of that point

So you can solve the problem, given the center of the circle at (a,b) and knowing the dimensions of the square box having side r...any given point (x,y) inside the box is also inside the circle if and only if:

((b-y)^2 + (a-x)^2) < r^2

Such a point resides outside or exactly on the circle if and only if this condition is false.

As Derek E. suggests in a comment, when implementing this solution it's better to compare the squared distance to avoid the approximations of the sqrt function.

这篇关于确定点是否位于特定的几何区域内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:30