这段代码是如何工作的?俯仰和偏航

问题描述

我最近在寻找如何为游戏创建简单的机器人,有两种方法可以做到这一点 1 是使用 atan2 和 sin 计算俯仰和偏航,例如

但是还有另一种方法人们如何计算它,我的问题是它是如何工作的?

This method I fully understand

代码

void CalcAngle(float *src,float *dst,float *angles)
{
    double delta[3] = {(src[0] - dst[0]),(src[1] - dst[1]),(src[2] - dst[2])};

    int x = 0;
    int y = 1;
    int z = 2;

    float hyp = delta[x] * delta[x] + delta[y] * delta[y];
    angles[0] = asinf(delta[z] / hyp) * 180 / pi;
    angles[1] = atanf(delta[y] / delta[x]) * 180 / pi;

    if(angles[0] > 0.0)
    {
        angles[1] += 180;
    }
}

以及我的想象人们是如何做到这一点的

Second which I don't understand

如果有人知道这段代码发生了什么,你能向我解释它是如何计算有效值的。例如,它无法计算第三和第二象限角,那么它甚至对其他人如何工作?以及为什么他们要计算三角形的相邻而不是斜边的对边?我不会问这个代码是不是单一案例,但我已经在很多案例中看到了。

For be more clear

解决方法

代码似乎确实是错误的。您应该使用 atan2 表示俯仰,使用 double hyp = sqrt(delta[x] * delta[x] + delta[y] * delta[y]); angles[0] = atan(delta[z] / hyp) * 180 / pi; // Pitch angles[1] = atan2(delta[y] / delta[x]) * 180 / pi; // Yaw if(angles[1] < 0.0) angles[1] += 180; 表示偏航。

<template>
  <div>
    <transition name="toast">
      <div id="slide" class="slide-modal" v-if="statuses.length">
        <div class="clear-notifications" @click='clearAllNotifications()'>Clear all notifications</div>
        <div v-for="status in statuses" :key="status.id" class="status-div">
          <div>{{ status.text }}</div>
          <div @click="closeStatus(status)"><span class="-x10-cross"></span></div>
        </div>
      </div>
    </transition>
  </div>
</template>

<script lang="ts">
  import { defineComponent,ref,computed,watch,onMounted } from "vue";
  import { useStore } from "../model/DataStore";
  export default defineComponent({ 
    setup() {
    const store = useStore();

    const statuses = ref([]);

    const statusMessage = computed(() => store.state.statusMessage);
    function  addStatus(newMessage) {

          statuses.value.push({
            id: statuses.value.length + 1,text: newMessage
          })
        }

      watch(statusMessage,(newValue: string,oldValue: string) => {
        addStatus(statusMessage.value);
      })

      onMounted(() => {
          window.addEventListener("scroll",function (e) {
                let vertical_position = 0;
                vertical_position = pageYOffset;

                if(document.getElementById("slide")){
                  document.getElementById('slide').style.bottom = -(vertical_position) + 'px';
                }
          });
      })

    return {
      store,statuses,addStatus
    };
  },methods: {
        clearAllNotifications() {
          this.statuses = []
        },closeStatus(elm: any) {
          const index = this.statuses.map((status) => status.id).indexOf(elm.id);
          this.statuses.splice(index,1);
        }
      }
  })
</script>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...