我知道如何将点移向 2D 空间的方向,它是这样的:
pointX += sin(angle) * movementSpeed;
pointY += cos(angle) * movementSpeed;
但假设 angle
变量被 pitch
、 yaw
和 roll
变量所取代,我如何在 3d 空格中做同样的事情?
(btw I 正在制作射线行进算法)
我知道如何将点移向 2D 空间的方向,它是这样的:
pointX += sin(angle) * movementSpeed;
pointY += cos(angle) * movementSpeed;
但假设 angle
变量被 pitch
、 yaw
和 roll
变量所取代,我如何在 3d 空格中做同样的事情?
(btw I 正在制作射线行进算法)
要使用 3D 空格移动一个点, 需要将这些角转换为方向矢量。 方向矢量描述此点移动的方向 。
#include <cmath>
// Convert degrees to radians if needed
constexpr float DEG_TO_RAD = M_PI / 180.0f;
// Function to move a point in 3D space
void movePointIn3DSpace(float& pointX, float& pointY, float& pointZ, float pitch, float yaw, float movementSpeed) {
// Convert angles to radians if they are in degrees
float pitchRad = pitch * DEG_TO_RAD;
float yawRad = yaw * DEG_TO_RAD;
// Calculate the direction vector
float dirX = cos(pitchRad) * sin(yawRad);
float dirY = sin(pitchRad);
float dirZ = cos(pitchRad) * cos(yawRad);
// Update the point s position
pointX += dirX * movementSpeed;
pointY += dirY * movementSpeed;
pointZ += dirZ * movementSpeed;
}
// Example usage
int main() {
float pointX = 0.0f, pointY = 0.0f, pointZ = 0.0f;
float pitch = 30.0f; // degrees
float yaw = 45.0f; // degrees
float movementSpeed = 1.0f;
movePointIn3DSpace(pointX, pointY, pointZ, pitch, yaw, movementSpeed);
// Output the new position
printf("New position: (%f, %f, %f)
", pointX, pointY, pointZ);
return 0;
}
(在 cpp btw 中编码)
I have the following available: last reported lat,lon w/timestamp target lat,lon estimated time to target heading How can I interpolate an estimated position over time? I know that s enough to ...
I am trying to add a table of contents for my LaTex document. The issue I am having is that this line: subsubsection{The expectation of (X^2)} Causes an error in the file that contains the ...
I am having a problem handling large numbers. I need to calculate the log of a very large number. The number is the product of a series of numbers. For example: log(2x3x66x435x444) though my actual ...
I have to write an algorithm in AS3.0 that plots the location of points radially. I d like to input a radius and an angle at which the point should be placed. Obviously I remember from geometry ...
I m using Electro in Lua for some 3D simulations, and I m running in to something of a mathematical/algorithmic/physics snag. I m trying to figure out how I would find the "spin" of a sphere of a ...
I have two rows of numbers ... 1) 2 2 1 0 0 1 2) 1.5 1 0 .5 1 2 Each column is compared to each other. Lower values are better. For example Column 1, row 2 s value (1.5) is more ...
I ve implemented this method in Javascript and I m roughly 2.5% out and I d like to understand why. My input data is an array of points represented as latitude, longitude and the height above the ...
Given a coordinate (lat, long), I am trying to calculate a square bounding box that is a given distance (e.g. 50km) away from the coordinate. So as input I have lat, long and distance and as output I ...