专业沈阳网站制作泰安网站建设推广
2026/4/6 5:39:44 网站建设 项目流程
专业沈阳网站制作,泰安网站建设推广,wordpress不显示子分类,怎么开发个人网站从两个点和一个宽度生成旋转矩形 宽度┌───────────┐│ │ P1●─┼───────────┼─●P2 长度 |P1P2|│ │└───────────┘宽度矩形中心 P1和P2的中点矩形长度 |P1P2| (两点距离)矩形宽度 输入的width参数矩形角度…从两个点和一个宽度生成旋转矩形宽度┌───────────┐ │ │ P1●─┼───────────┼─●P2 长度 |P1P2| │ │ └───────────┘ 宽度矩形中心 P1和P2的中点矩形长度 |P1P2| (两点距离)矩形宽度 输入的width参数矩形角度 向量P1P2的方向void__fastcallpoint_point_width_to_rrect(doublex1,// 第一个点xdoubley1,// 第一个点ydoublex2,// 第二个点xdoubley2,// 第二个点ydoublewidth,// 矩形宽度float*out// 输出旋转矩形参数){// 计算矩形的方向向量doubledxx2-x1;// x方向差值doubledyy2-y1;// y方向差值// 计算矩形的中心点两点中点floatcenter_y(y1y2)*0.5f;floatcenter_x(x1x2)*0.5f;out[1]center_y;// 中心点y坐标out[0]center_x;// 中心点x坐标// 计算两点间距离这是矩形的长度doubledistance_sqdx*dxdy*dy;doubledistancesqrt(distance_sq);// 半长 长度的一半floathalf_lengthdistance*0.5f;out[4]width;// 矩形的宽度out[3]half_length;// 矩形的一半长度// 计算矩形的旋转角度// atan2(dx, dy) 计算线段与y轴的夹角// 转换为度并减去90度得到标准数学角度floatangleatan2(dx,dy)*180.0f/3.141592653589793f-90.0f;out[2]angle;// 旋转角度}计算旋转矩形的四个顶点坐标。输出是12个double所以可能是6个点每个点x,y。#includecmath// 计算旋转矩形的顶点// 输入: center_x, center_y, angle_deg, half_width, half_height// 输出: 6个点可能是闭合多边形的顶点包括起点重复voidcalculate_rotated_rectangle(floatcenter_x,floatcenter_y,floatangle_deg,floathalf_width,floathalf_height,double*output)// 输出数组12个元素{// 角度加90度后转弧度可能是坐标系统不同doublerad(angle_deg90.0)*M_PI/180.0;doublecos_acos(rad);doublesin_asin(rad);// 计算矩形的轴向量// 由于角度加了90°所以// 水平轴方向: (sin_a, cos_a) // 对应宽度方向// 垂直轴方向: (-cos_a, sin_a) // 对应高度方向doublewidth_vec_xsin_a*half_width;doublewidth_vec_ycos_a*half_width;doubleheight_vec_x-cos_a*half_height;doubleheight_vec_ysin_a*half_height;// 计算四个顶点// 顶点0: 中心 - 宽度向量 - 高度向量output[0]center_x-width_vec_x-height_vec_x;output[1]center_y-width_vec_y-height_vec_y;// 顶点1: 中心 宽度向量 - 高度向量output[2]center_xwidth_vec_x-height_vec_x;output[3]center_ywidth_vec_y-height_vec_y;// 顶点2: 中心 宽度向量 高度向量output[4]center_xwidth_vec_xheight_vec_x;output[5]center_ywidth_vec_yheight_vec_y;// 顶点3: 中心 - 宽度向量 高度向量output[6]center_x-width_vec_xheight_vec_x;output[7]center_y-width_vec_yheight_vec_y;// 如果输出是6个点12个double可能是// 四个顶点 第一个顶点重复形成闭合多边形output[8]output[0];// 重复第一个点output[9]output[1];output[10]output[2];// 或者可能是中心点output[11]output[3];}这是一个计算旋转矩形6个顶点的函数可用于绘制带边框的矩形4个外角 2个内角或其他特定的碰撞检测形状或者只是简单地计算矩形的4个角但数组分配了12个元素实际只用了8个关键点输入角度加了90°因为图像坐标系Y轴向下a1[3]和a1[4]是半宽和半高通过旋转矩阵计算矩形的四个角点坐标生成圆弧卡尺/** * 生成圆形卡尺测量点 * * param center_x 圆心X坐标 * param center_y 圆心Y坐标 * param radius 测量半径 * param width 卡尺宽度 * param step_angle 角度步长控制度 * param direction 方向0顺时针0逆时针 * param num_points 指定点数0时自动计算 * param buffer_mgr 缓冲区管理器 * return 成功返回0失败返回-1 */ int generate_circular_caliper_points( double center_x, double center_y, double radius, double width, double step_angle, // 控制点密度 int direction, int num_points, BufferManager buffer_mgr ) { // 1. 计算分段数 int segments num_points; if (segments 0) { // 自动计算圆周长 / (step_angle * 3) // 这里 step_angle 是角度需要转弧度 double step_rad step_angle * DEG_TO_RAD; double circumference radius * TWO_PI; segments static_castint(circumference / (step_rad * 3.0)); } // 确保不超过最大合理分段数 double max_segments radius * TWO_PI / (step_angle * DEG_TO_RAD * 3.0); if (segments max_segments) { segments static_castint(max_segments); } if (segments 0) { return -1; // 错误 } // 2. 确保缓冲区足够 buffer_mgr.ensure_capacity(segments); // 3. 角度增量 double angle_increment TWO_PI / segments; // 4. 生成测量点 for (int i 0; i segments; i) { // 计算当前角度 double angle_rad i * angle_increment; // 计算测量点坐标 double x center_x sin(angle_rad) * radius; double y center_y cos(angle_rad) * radius; // 计算测量方向角度 // 圆上点的法线方向是径向方向 double normal_angle_rad angle_rad; // 从圆心指向测量点的方向 double measure_angle_deg normal_angle_rad * RAD_TO_DEG; // 方向调整 if (direction 0) { // 顺时针 measure_angle_deg - 90.0f; // 垂直于法线方向 } else { // 逆时针 measure_angle_deg measure_angle_deg - 90.0f 180.0f; } // 规整化角度到 [0, 360) while (measure_angle_deg 360.0) measure_angle_deg - 360.0; while (measure_angle_deg 0.0) measure_angle_deg 360.0; // 写入缓冲区 CaliperPoint* point buffer_mgr.get_current(); point-x static_castfloat(x); point-y static_castfloat(y); point-angle static_castfloat(measure_angle_deg); point-param1 static_castfloat(width); // 存储宽度 point-param2 static_castfloat(step_angle); // 存储步长参数 buffer_mgr.advance(1); } return 0; // 成功 }测量函数// 核心测量函数MeasurementResultmeasure(constunsignedchar*image_data,intimage_width,intimage_height,constMeasurementParamsparams,constchar*edge_select_modestrongest){MeasurementResult result;// 1. 计算方向向量doubleangle_rad(params.angle_deg90.0)*M_PI/180.0;doublecos_acos(angle_rad);doublesin_asin(angle_rad);// 2. 沿宽度方向生成采样点intwidth_samples(int)(2*params.width1);std::vectordoublesample_points_x(width_samples);std::vectordoublesample_points_y(width_samples);for(inti0;iwidth_samples;i){doubleoffseti-params.width;sample_points_x[i]params.start_xoffset*sin_a;sample_points_y[i]params.start_yoffset*cos_a;}// 3. 对每个采样点沿高度方向采样强度剖面intheight_samples(int)(2*params.height1);std::vectorstd::vectordoubleintensity_profiles(width_samples);std::vectordoubleaverage_intensities(width_samples,0.0);for(inti0;iwidth_samples;i){std::vectordoubleprofileintensity_profiles[i];profile.resize(height_samples);doublesum0.0;for(intj0;jheight_samples;j){doublevert_offsetj-params.height;// 计算采样点坐标doublepxsample_points_x[i]vert_offset*(-cos_a);doublepysample_points_y[i]vert_offset*sin_a;// 像素插值doublepixel_value0.0;if(config_.interpolation_type0){pixel_valuebilinear_interpolate(image_data,image_width,image_height,px,py);}else{pixel_valuebicubic_interpolate(image_data,image_width,image_height,px,py);}profile[j]pixel_value;sumpixel_value;}average_intensities[i]sum/height_samples;}// 4. 高斯滤波std::vectordoublegaussian_kernel;generate_gaussian_kernel(gaussian_kernel,config_.sigma);std::vectordoublesmoothed_intensities;gaussian_filter_1d(average_intensities,smoothed_intensities,gaussian_kernel);// 5. 计算一阶导数std::vectordoublederivatives;compute_derivative(smoothed_intensities,derivatives);// 6. 检测边缘std::vectorEdgeInfoedges;detect_edges(derivatives,smoothed_intensities,edges,config_.threshold);result.edge_count(int)edges.size();if(edges.empty()){returnresult;// 没有检测到边缘}// 7. 边缘选择EdgeInfo selected_edge;if(!select_edge(edges,edge_select_mode,selected_edge)){returnresult;// 选择失败}// 8. 转换为世界坐标doubleworld_offset(selected_edge.position-width_samples/2.0);doubleedge_xparams.start_xworld_offset*sin_a;doubleedge_yparams.start_yworld_offset*cos_a;// 9. 返回结果result.successtrue;result.edge_xedge_x;result.edge_yedge_y;result.edge_strengthselected_edge.strength;returnresult;}

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询