指定R语言中的ox.scale参数来定义X轴的显示类型

100 篇文章 ¥59.90 ¥99.00
本文介绍了R语言中ox.scale参数的用法,包括连续型、序数型、对数型、类别型和日期时间型等不同类型的X轴设置,以适应不同类型的数据展示需求。通过示例代码,读者可以了解如何根据数据特点选择合适的刻度类型。

指定R语言中的ox.scale参数来定义X轴的显示类型

在R语言中,绘制数据图表时,ox.scale参数是一个非常有用的选项,它允许我们指定X轴的显示类型。通过设置不同的参数值,我们可以根据数据的特点选择合适的刻度类型,从而更好地呈现数据。在本文中,我们将探讨一些常见的ox.scale参数值及其用法,并给出相应的源代码示例。

  1. “continuous”(连续型)
    当我们的数据是连续的数值型数据时,我们可以使用"continuous"参数值来设置X轴为连续型。这是默认的参数值,它会根据数据的范围自动确定刻度间隔。
# 创建一个简单的数据集
x <- 1:10
y <- rnorm(10)

# 绘制散点图,并设置X轴为连续型
plot(x, y, xaxs = "continuous", main = "连续型X轴")
  1. “ordinal”(序数型)
    当我们的数据表示某种排序关系时,可以使用"ordinal"参数值来设置X轴为序数型。序数型数据通常表示类别或有序类别。
# 创建一个带有类别的数据集
x <- c("A", "B", "C", "D")
y <- 1:4

# 绘制条形图,并设置X轴为序数型
barplot(y, names.arg = x, xaxs = "ordinal", main = "序数型X轴")
  1. “log”(对数型)
    当我们的数
/** ****************************************************************************** * @file :geometry_3d.c * @date :2025-12-16 * @brief :三维平面几何函数定义 * *------------------------------History Record------------------------------- * @modifier : * * @date : ****************************************************************************** **/ /*Include ---------------------------------------------------------------*/ #include "geometry_3d.h" #include <math.h> /*private define --------------------------------------------------------*/ /*private TypeDef -------------------------------------------------------*/ /*Fucntions--------------------------------------------------------------*/ /* Private Functions--------------------------------------*/ /**** * @brief 向量减法(a - b) * @param a 点坐标 b 点坐标 **/ static point_3d_t vector_sub(point_3d_t a, point_3d_t b) { return (point_3d_t){a.x - b.x, a.y - b.y, a.z - b.z}; } /**** * @brief 向量加法(a + b) * @param a 点坐标 b 点坐标 **/ static point_3d_t vector_add(point_3d_t a, point_3d_t b) { return (point_3d_t){a.x + b.x, a.y + b.y, a.z + b.z}; } /**** * @brief 向量缩放 * @param v 输入向量 s 缩放因子 **/ static point_3d_t vector_scale(point_3d_t v, float s) { return (point_3d_t){v.x * s, v.y * s, v.z * s}; } /**** * @brief 向量点乘(a ·b = ax*bx + ay*by + az*bz) * @param a 点坐标 b 点坐标 **/ static float vector_dot(point_3d_t a, point_3d_t b) { return a.x * b.x + a.y * b.y + a.z * b.z; } /**** * @brief 向量叉乘(a ×b,用于计算平面法向量) * @param a 点坐标 b 点坐标 **/ static point_3d_t vector_cross(point_3d_t a, point_3d_t b) { return (point_3d_t){ a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x }; } /**** * @brief 标准化射线方向向量(转为单位向量) * @param **/ static point_3d_t vector_normalize(point_3d_t v) { float mag = sqrtf(vector_dot(v, v)); if (mag < EPSILON_3D) return v; return vector_scale(v, 1.0f / mag); } /* Public Functions --------------------------------------*/ /**** * @brief 计算两点之间的三维欧氏距离 * @param a 点坐标 b 点坐标 **/ float point_distance_3d(point_3d_t a, point_3d_t b) { float dx = a.x - b.x; float dy = a.y - b.y; float dz = a.z - b.z; return sqrtf(dx*dx + dy*dy + dz*dz); } /**** * @brief 球管射线方向计算 (已知起点和 Z夹角,创建射线结构体) * @param origin:起点 angle_z_deg:Z夹角 **/ ray_3d_t create_ray_from_angle(point_3d_t origin, float theta_z) { // θ_z 是射线与Z的夹角(弧度) ray_3d_t ray; ray.origin = origin; // 计算方向向量(假设在XZ平面) ray.direction.x = sinf(theta_z); ray.direction.y = 0.0f; ray.direction.z = cosf(theta_z); // 归一化方向向量 ray.direction = vector_normalize(ray.direction); return ray; } /**** * @brief 创建与Z平行的空间矩形 空间矩形坐标计算(翻斗不翻转情况) * @param mid_point:射线中线点(矩形中心点),width:X方向长度,height:Y方向长度 **/ rect_3d_t create_rect_from_ray(ray_3d_t ray, float width, float height) { rect_3d_t rect; rect.center = ray.origin; // 计算局部坐标系基向量 point_3d_t world_up = {0, 1, 0}; point_3d_t local_x = vector_normalize(vector_cross(world_up, ray.direction)); point_3d_t local_y = vector_normalize(vector_cross(ray.direction, local_x)); // 计算半宽高 float half_width = width / 2.0f; float half_height = height / 2.0f; // 计算四个角点 rect.left_top = vector_add(rect.center, vector_add( vector_scale(local_x, -half_width), vector_scale(local_y, half_height) )); rect.left_bot = vector_add(rect.center, vector_add( vector_scale(local_x, -half_width), vector_scale(local_y, -half_height) )); rect.right_bot = vector_add(rect.center, vector_add( vector_scale(local_x, half_width), vector_scale(local_y, -half_height) )); rect.right_top = vector_add(rect.center, vector_add( vector_scale(local_x, half_width), vector_scale(local_y, half_height) )); return rect; } /**** * @brief 三维矩形转换为平面方程(Ax + By + Cz + D = 0) * @param **/ plane_3d_t rect_to_plane(rect_3d_t rect) { plane_3d_t plane; // 计算两个边向量 point_3d_t v1 = vector_sub(rect.right_top, rect.left_top); point_3d_t v2 = vector_sub(rect.left_bot, rect.left_top); // 计算法向量(叉积) point_3d_t normal = vector_cross(v1, v2); normal = vector_normalize(normal); // 平面方程: Ax + By + Cz + D = 0 plane.A = normal.x; plane.B = normal.y; plane.C = normal.z; plane.D = -(plane.A * rect.center.x + plane.B * rect.center.y + plane.C * rect.center.z); return plane; } /**** * @brief 判断射线与平面是否有交点 * @param **/ // 射线方程:P = origin + t*direction(t≥0) // 平面方程:A*x + B*y + C*z + D = 0 // 推导:A*(ox + t*dx) + B*(oy + t*dy) + C*(oz + t*dz) + D = 0 → t = -(A*ox + B*oy + C*oz + D)/(A*dx + B*dy + C*dz) bool ray_plane_intersection(ray_3d_t ray, plane_3d_t plane, point_3d_t* intersection) { float denom = vector_dot(ray.direction, (point_3d_t){plane.A, plane.B, plane.C}); // 检查平行情况 if (fabsf(denom) < EPSILON_3D) { return false; } // 计算交点参数 t point_3d_t diff = vector_sub(ray.origin, (point_3d_t){0, 0, 0}); float num = -(plane.A * ray.origin.x + plane.B * ray.origin.y + plane.C * ray.origin.z + plane.D); float t = num / denom; // 检查是否在射线正方向 if (t < 0) return false; // 计算交点坐标 intersection->x = ray.origin.x + t * ray.direction.x; intersection->y = ray.origin.y + t * ray.direction.y; intersection->z = ray.origin.z + t * ray.direction.z; return true; } /**** * @brief 判断点是否在三维矩形内 * @param **/ // 方法:通过向量投影判断点是否在矩形的X-Y边界内(矩形平面垂直于Z时等价于2D判断) bool is_point_in_rect(point_3d_t point, rect_3d_t rect) { // 计算局部坐标系基向量 point_3d_t v1 = vector_sub(rect.right_top, rect.left_top); point_3d_t v2 = vector_sub(rect.left_bot, rect.left_top); point_3d_t normal = vector_cross(v1, v2); // 构建局部坐标系 point_3d_t local_x = vector_normalize(v1); point_3d_t local_y = vector_normalize(vector_cross(normal, local_x)); // 计算点到矩形中心的向量 point_3d_t vec_to_point = vector_sub(point, rect.center); // 计算在局部坐标系中的投影 float proj_x = vector_dot(vec_to_point, local_x); float proj_y = vector_dot(vec_to_point, local_y); // 计算矩形半宽高 float half_width = point_distance_3d(rect.left_top, rect.right_top) / 2.0f; float half_height = point_distance_3d(rect.left_top, rect.left_bot) / 2.0f; // 检查是否在矩形边界内 return (fabsf(proj_x) <= half_width + EPSILON_3D) && (fabsf(proj_y) <= half_height + EPSILON_3D); } /**** * @brief 计算射线与三维矩形的交点 * @param **/ point_3d_t ray_rect_intersection(ray_3d_t ray, rect_3d_t rect) { point_3d_t intersection = {NULL, NULL, NULL};//NAN // 转换矩形为平面方程 plane_3d_t plane = rect_to_plane(rect); // 求射线与平面交点 if (ray_plane_intersection(ray, plane, &intersection)) { // 检查交点是否在矩形内 if (is_point_in_rect(intersection, rect)) { return intersection; } } // 无交点返回 return (point_3d_t){NULL, NULL, NULL}; } /**** * @brief 计算点在平面上的垂直投影 * @param **/ point_3d_t project_point_to_plane(point_3d_t point, plane_3d_t plane) { // 计算平面法向量 point_3d_t normal = {plane.A, plane.B, plane.C}; float mag = sqrtf(vector_dot(normal, normal)); if (mag < EPSILON_3D) return point; // 归一化法向量 normal = vector_scale(normal, 1.0f / mag); // 计算点到平面的距离 float dist = (plane.A * point.x + plane.B * point.y + plane.C * point.z + plane.D) / mag; // 计算投影点 return (point_3d_t){ point.x - dist * normal.x, point.y - dist * normal.y, point.z - dist * normal.z }; } /**** * @brief 已知球管旋转角度,求射线在目标平面的投影 * @param **/ point_3d_t ray_plane_3d_project_with_rotation(ray_3d_t ray, rect_3d_t* target_rect, float rotate_angle_y_deg) { if (target_rect == NULL) return ray.origin; // 将射线起点绕 Y旋转(模拟球管旋转) float angle_rad = rotate_angle_y_deg * M_PI / 180.0f; float cos_a = cosf(angle_rad); float sin_a = sinf(angle_rad); point_3d_t rotated_origin; // 绕 Y旋转矩阵:X'=X*cosθ - Z*sinθ,Y'=Y,Z'=X*sinθ + Z*cosθ rotated_origin.x = ray.origin.x * cos_a - ray.origin.z * sin_a; rotated_origin.y = ray.origin.y; rotated_origin.z = ray.origin.x * sin_a + ray.origin.z * cos_a; // 获取目标平面方程 plane_3d_t target_plane = rect_3d_to_plane(target_rect); // 计算旋转后射线起点在目标平面的垂直投影 point_3d_t project_point = point_plane_3d_project(rotated_origin, target_plane); return project_point; } /*-------------------------end of file --------------------------------*/ 根据我当前代码,生成一个测试用例代码。帮我写个测试用例代码来进行测试,名字叫geometry_3d_test.c和geometry_3d_test.h。我使用stm32f207vet6使用keil5写代码,使用SEGGER_RTT_printf来进行log信息打印,帮我写个测试用例代码
12-23
# 初始模拟系统设置 units metal dimension 3 boundary p p p atom_style atomic neighbor 2.0 bin timestep 0.001 neigh_modify delay 0 every 10 check yes atom_modify map hash # 区域定义 region hezi block -3 303 -3 303 -5 300 create_box 5 hezi mass 1 47.867 # Ti mass 2 26.9815 # Al mass 3 26.9815 # Al (热浴层) mass 4 26.9815 # Al (边界层) mass 5 12 # C (金刚石球) # 读取data文件 read_data final_poly.lmp add append shift 0 0 0 #设置区域和原子组 region boundary_layer block 0 300 0 300 0 10 units box region thermostat_layer block 0 300 0 300 10 20 units box region newtonian_layer block 0 300 0 300 20 180 units box region workpiece union 3 newtonian_layer thermostat_layer boundary_layer #工件 #定义计算相关信息,固定原子 group boundary_layer region boundary_layer #边界层原子(通常固定边界) group newtonian_layer region newtonian_layer #牛顿力学层(不受热浴控制,遵循经典牛顿力学) group thermostat_layer region thermostat_layer #热浴层(通过温度控制维持恒温) region mobile union 2 newtonian_layer thermostat_layer units box #将newtonian_layer与thermostat_layer合为mobile组(位移层) group mobile region mobile group workpiece region workpiece #工件组 ### 定义原子间相互作用势 pair_style hybrid meam/c tersoff morse 2.05 pair_coeff * * meam/c library.meam Al Ti TiAl.meam Ti Al Al Al NULL pair_coeff * * tersoff SiC.tersoff NULL NULL NULL NULL C pair_coeff 1 5 morse 0.982 2.283 1.892 #Ti C pair_coeff 2*4 5 morse 0.4691 1.738 2.246 #Al C #温度初始化 velocity all create 300 482748 rot yes dist gaussian #高斯分布 对所有原子进行速度初始化,总体系的温度为300k,4928459为随机数,每个原子的速度被随机设置 #------------------------能量最小化 弛豫---------------------------- min_style cg minimize 1.0e-14 1.0e-14 100 100 compute new mobile temp #计算mobile原子组的温度 compute T1 newtonian_layer temp compute 1 mobile ke compute 2 mobile ke/atom #意思是计算每个原子的动能,计算名称为2(这个名称可以是数字,也可以是字符串,随个人风格) variable yuanziwendu atom c_2/1.5/8.617343e-5 #固定的格式 compute mytemp thermostat_layer temp compute 8 mobile displace/atom fix 0 mobile nvt temp 300 300 0.1 drag 0.1 #0.1 z 0.0 0.0 0.1 #fix语句ID标识符 原子组标识 温度标识 初始温度 结束温度 阻尼系数 #热力输出 thermo 200 thermo_style custom step temp etotal pe ke press c_new c_mytemp c_T1 #c_1 c_7 c_new1 thermo_modify lost ignore #弛豫步数 dump 1 all custom 1000 whs.lammpstrj id type x y z run 500 unfix 0 undump 1 #金刚石球建模 lattice diamond 3.52 region tool sphere 30 150 245 25 units box #x y z r create_atoms 3 region tool region ball block 0 250 0 250 200 300 units box group ball region tool #---------------------- 命令改变原子的类型 ---------------------- set group boundary_layer type 3 #将boundary_layer组内的原子定义类型3 set group thermostat_layer type 4 set group ball type 5 write_data whsfc.data #-----------------------------删除原子----------------- region duoyu block 0 300 0 300 280 300 units box group duoyu region duoyu delete_atoms group duoyu displace_atoms ball move 0 0 -38 units box write_data whsdong.data #----------------------------------应力应变---------------------------------- compute peratom mobile stress/atom NULL #计算每个原子的应力 compute 6 ball group/group workpiece variable press atom "sqrt(((c_peratom[1]/10000-c_peratom[2]/10000)^2+(c_peratom[2]/10000-c_peratom[3]/10000)^2+(c_peratom[1]/10000-c_peratom[3]/10000)^2+6*((c_peratom[4]/10000)^2+(c_peratom[5]/10000)^2+(c_peratom[6]/10000)^2))/2)" fix 10 mobile ave/atom 1 5000 5000 v_yuanziwendu fix 11 mobile ave/atom 1 10000 10000 v_yuanziwendu fix 12 mobile ave/atom 1 20000 20000 v_yuanziwendu fix 13 mobile ave/atom 1 40000 40000 v_yuanziwendu fix 14 mobile ave/atom 1 2000 2000 v_press fix 15 mobile ave/atom 1 5000 5000 v_press fix 16 mobile ave/atom 1 10000 10000 v_press dump 3 all custom 10000 00d1f3.lammpstrj id type x y z f_10 f_11 c_8[4] f_14 f_15 f_16 dump 4 all custom 20000 00d1f4.lammpstrj id type x y z f_10 f_11 f_12 c_8[4] dump 5 all custom 40000 00d1f5.lammpstrj id type x y z f_10 f_11 f_12 f_13 fix 1 mobile nve fix 2 boundary_layer setforce 0.0 0.0 0.0 fix 3 ball nve #fix 4 tool setforce NULL NULL NULL #将tool在xy方向上的受力设为0,z方向受力保持原不变 fix 4 ball setforce 0.0 0.0 NULL #将tool在xy方向上的受力设为0,z方向受力保持原不变 fix 5 ball aveforce 0.0 0.0 -0.008 #修复命令 fx,fy,fz = 力分量(力单位 #fix 5 tool aveforce 0.0 0.0 -0.003 #修复命令 fx,fy,fz = 力分量(力单位 #velocity tool set 0.0 0.0 -1.0 units box velocity thermostat_layer create 300 12345 dist gaussian fix 6 thermostat_layer temp/rescale 1 300 300 0.01 1.0 fix_modify 6 temp mytemp thermo_style custom step temp etotal pe ke press c_new v_dz c_mytemp c_T1 c_6 c_6[1] c_6[2] c_6[3] thermo_modify lost ignore timestep 0.001 thermo 500 variable A equal 15 #variable T equal 10.0 variable T equal 15.0 variable omega equal 3.0*PI/$T #variable x equal "1*step*dt" variable x equal "0.5*step*dt" #variable x equal "2*step*dt" variable y equal swiggle(0.0,$A,$T) fix 7 tool move variable v_x v_y NULL NULL NULL NULL units box #fix 9 tool move variable v_x v_y NULL NULL NULL NULL units box velocity tool set 0.0 0.0 0.0 #给刀具设置速度 #velocity tool set 4.0 3.0 0.0 #给刀具设置速度 dump 2 all custom 500 1.lammpstrj5 id type x y z run 400000 # 平移分量:沿Y移动 fix trans ball move linear 0 1.0 0 # 旋转分量:绕Z旋转(周期5ps) fix rot ball move rotate origin ${x0} ${y0} ${z0} axis 0 0 1 period 5 # 运动合成 fix combo ball add fix trans fix rot怎末使用
09-17
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值