check if coordinates are inside the hexagon

版本 1.0.0.0 (1.5 KB) 作者: Yuanye Wang
check if coordinates are within the hexagon, can be used to filter out positions outside.
460.0 次下载
更新时间 2011/11/30

查看许可证

check if the position(s) are inside a hexagon

pos: coordinates of the positions, size (#positions, 2);
radius: radius or edge length of the hexagon
center: of the hexagon, by default is [0 0]
rotation: of the hexagon, by default is 0 degree
output: a bool vector of size (#positions, 1); true if inside.

by Yuanye Wang, Powerwave Technologies
yuanye.wang@pwav.com

An example is given below, which generates positions inside a hexagon with edge length 10, center position [3 10], and rotated 40 degree:

clear all; close all; clc
center = [3 10];
radius = 10;
rotation = 40;
pos = randn(50000,2) * radius + repmat(center, 50000,1);
x = inside_hex(pos, radius, center, rotation);
plot(pos(x,1),pos(x,2),'o')

引用格式

Yuanye Wang (2024). check if coordinates are inside the hexagon (https://www.mathworks.com/matlabcentral/fileexchange/34020-check-if-coordinates-are-inside-the-hexagon), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2009a
兼容任何版本
平台兼容性
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0