Relative position (in 3d)

Started by vitovc, Jan 26, 2024, 01:08 PM

Previous topic - Next topic

vitovc

I'd wanted to share some functions from my vc-mp archive.

This function will find relative position based by z_angle (vertical angle) and relative X and Y distance from base point.
rel_pos2d <- function(z_angle, pos_x, pos_y, pos_z, rel_x, rel_y, rel_z){
  local rX = pos_x + rel_x * ::cos(z_angle) - rel_y * ::sin(z_angle);
  local rY = pos_y + rel_x * ::sin(z_angle) + rel_y * ::cos(z_angle);
  local rZ = pos_z + rel_z;
  return ::Vector(rX, rY, rZ);
}

This function will find relative position based by z_angle (vertical angle), y_angle (horizontal angle) and distance.
rel_pos3d <- function(dist, pos_x, pos_y, pos_z, y_angle, z_angle){
  local rX = dist * ::cos(y_angle) * ::cos(z_angle);
  local rY = dist * ::cos(y_angle) * ::sin(z_angle);
  local rZ = dist * ::sin(y_angle);
  return ::Vector(pos_x + rX, pos_y + rY, pos_z + rZ);
}
...::: vice city :::...

PSL