三维场景中斜抛运动顶点的生成

本文介绍了一种在三维场景中实现斜抛运动的算法,详细讲解了如何通过给定的初始条件和物理参数,计算斜抛运动轨迹上的顶点坐标,包括落地点的确定和整个运动路径的生成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

三维场景中斜抛运动顶点的生成

1 算法思想-斜抛运动

在这里插入图片描述

2 代码

void getparabola_vertex_2(glm::vec3 _Point, float _thetaAngle, float _fanAngle)
{
	float thetaAngle = radians(_thetaAngle);//斜角
	float fanAngle = radians(_fanAngle);//手柄指向和x轴的夹角;
	//第一个点
	float x;
	float y;
	float z;
	/*x_start = x;
	y_start = y;
	z_start = z;
	startPoint = glm::vec3(x_start, y_start, z_start);*/

	float v0 = 8;
	float te = 0;
	float av = 10;
	//计算落地点需要的时间
	float parameter_a = -0.5 * av;
	float parameter_b = v0 * sin(thetaAngle);
	float parameter_c = _Point.y;
	float x_solution = getSolution_qe_one_variable(parameter_a, parameter_b, parameter_c);//一次二次方程的解,可以这篇文章的参考文献
	te = x_solution;
	glm::vec3 pointFall;
	float pointfall_y = parameter_c + parameter_b * te + parameter_a * pow(te, 2);
	//float xTrajectory = 0;
	//float pointfall;
	float pointfall_x;
	float pointfall_z;
	float v1;
	float v2;
	/*if (_fanAngle!=0)
	{*/
	v1 = v0 * cos(thetaAngle)*cos(fanAngle);//x轴方向的速度
	v2 = v0 * cos(thetaAngle)*sin(fanAngle);//z轴方向的速度
	pointfall_x = _Point.x + v1 * te;
	pointfall_z = _Point.z + v2 * te;
	/*}
	else
	{
		pointfall_x= _Point.x+ v0 * cos(thetaAngle)*te;
		pointfall_z = _Point.z;
		xTrajectory = _Point.x;
	}*/


	pointFall = glm::vec3(pointfall_x, pointfall_y, pointfall_z);//落地点的坐标
	//t=sqrt(_Point.y)
	//计算顶点
	float t = 0;
	y = parameter_c + parameter_b * t + parameter_a * pow(t, 2);
	float step = te / 15;
	for (int i = 0; i < 16; i++, t = t + step, y = parameter_c + parameter_b * t + parameter_a * pow(t, 2))
	{
		//xTrajectory = xTrajectory + v0 * cos(thetaAngle)*t;
		x = _Point.x + v1 * t;
		z = _Point.z + v2 * t;
		/*if (_fanAngle != 0)
		{

			x = xTrajectory * sin(fanAngle);
			z = xTrajectory * cos(fanAngle);
		}
		else
		{
			x = _Point.x + v0 * cos(thetaAngle)*t;
			z = _Point.z;
			xTrajectory = _Point.x;
		}*/
		if (i == 15)
		{
			//最后一个坐标放落地点坐标,这个坐标很重要,需要自己
			teleportation_2[0 + 6 * 15] = pointFall.x;
			teleportation_2[1 + 6 * 15] = 0;
			teleportation_2[2 + 6 * 15] = pointFall.z;
			teleportation_2[3 + 6 * 15] = 0.5;
			teleportation_2[4 + 6 * 15] = 0.0;
			teleportation_2[5 + 6 * 15] = 0.5;
		}
		else
		{

			teleportation_2[0 + 6 * i] = x;
			teleportation_2[1 + 6 * i] = y;
			teleportation_2[2 + 6 * i] = z;
			teleportation_2[3 + 6 * i] = 0.5;
			teleportation_2[4 + 6 * i] = 0.0;
			teleportation_2[5 + 6 * i] = 0.5;
		}
	}
	//遍历顶点数组
	/*for (int i = 0; i < num_vertex * 6; i++)
	{
		cout << teleportation[i] << " ";
		if ((i + 1) % 6 == 0)
		{
			cout << endl;
		}
	}*/
}

3 参考文献

[1].求解一元二次方程的根c++

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值