View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
check if coordinates are inside the hexagon

5.0 | 1 rating Rate this file 4 Downloads (last 30 days) File Size: 1.46 KB File ID: #34020 Version: 1.0
image thumbnail

check if coordinates are inside the hexagon


Yuanye Wang (view profile)


check if coordinates are within the hexagon, can be used to filter out positions outside.

| Watch this File

File Information

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

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);

Required Products MATLAB
MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
19 Mar 2013 Ken Purchase

Simple and elegant - thanks!

Contact us