判断点是否位于3D检测框中

给定一个检测框[cx,cy,cz,w,h,l,head],判断点(x,y,z)是否位于该检测框内。
在这里插入图片描述

c++版本

bool check_point_in_box(float* points, float* box, float local_x, float local_y){
  //points:[x,y,z]
  //box:[c_x,c_y,c_z,dx,dy,dz,heading]
  float x = points[0], y = points[1], z = points[2];
  float cx = box[0], cy = box[1], cz = box[2];
  float dx = box[3], dy = box[4], dz = box[5], rz = box[6];
  // trans the coordinate to the local coordinate
  float shift_x = x - cx;
  float shift_y = y - cy;
  float cos_a = cos(rz), sin_a = sin(rz);
  local_x = shift_x * cos_a + shift_y * sin_a;
  local_y = shift_y * cos_a - shift_x * sin_a;
  if (abs(z - cz) > dz / 2.0)return false;
  if(abs(local_x) > dx / 2.0 || abs(local_y)>dy/2.0)return false;
  return true;
}

python 版本

import math
def check_point_in_box(pts, box):
	"""
	pts[x,y,z]
	box[c_x,c_y,c_z,dx,dy,dz,heading]
"""
shift_x = pts[0] - box[0]
shift_y = pts[1] - box[1]
shift_z = pts[2] - box[2]
cos_a = math.cos(box[6])
sin_a = math.sin(box[6])
dx,dy,dz = box[3], box[4], box[5]
local_x = shift_x * cos_a + shift_y * sin_a;
local_y = shift_y * cos_a - shift_x * sin_a;
if(abs(shift_z)>dz/2.0||abs(local_x)>dx/2.0||abs(local_y)>dy/2.0):
	return False
return True
  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值