首页 > 解决方案 > 如何从另一个顶点中减去一个顶点?

问题描述

对于我的 uni 分配,我需要从另一个顶点中减去一个顶点

任务:通过从顶点 0 中减去顶点 1 来构造向量 a。

教授给了我们方法的主体,我们需要填充它,以便为每个顶点工作

方法的主体:

Vector MinusToVector(const Vertex &other) const;

使用方法:

向量 VectorA = 顶点 1. MinusToVector(vertex0);

我为这个任务奋斗了一个多小时,我做不到

标签: c++gdi

解决方案


This usually works:

Vector Vector::MinusToVector(const Vertex &other) const {
  return Vertex(this->X - other.x, this->y - other.y, this->z - other.z);
}

By the way your professor gave you the declaration, not the body of the method.

Make sure to include the declaration inside the Vector class/struct body.


推荐阅读