普通网友 2022-08-06 11:54 采纳率: 25%
浏览 18
已结题

omnet中获取了节点坐标后如何在发送信息时获取两个节点之间距离。

这是我找到的一段获取节点坐标的cc代码,但是之后怎么获取两个节点之间的距离?还望有人能给出具体方法。
#include <string.h>
#include <omnetpp.h>

class Txc2 : public cSimpleModule
{
private:
//添加模块坐标属性
const char *positionX;
const char *positionY;
protected:
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};

Define_Module(Txc2);

void Txc2::initialize()
{
if (strcmp("tic", getName()) == 0)
{
// The ev' object works like cout' in C++.
EV << "Sending initial message\n";
cMessage *msg = new cMessage("tictocMsg");
send(msg, "out");
}
}

void Txc2::handleMessage(cMessage *msg)
{
EV <<"获取坐标\n";
cDisplayString& dispStr = getDisplayString();
positionX = dispStr.getTagArg("p", 0);
positionY = dispStr.getTagArg("p", 1);
EV<<positionX<< endl;
EV<<positionY<< endl;

// msg->getName() is name of the msg object, here it will be "tictocMsg".
EV << "Received message `" << msg->getName() << "', sending it out again\n";
send(msg, "out");

}

  • 写回答

2条回答 默认 最新

  • 来灵 2022-08-06 12:09
    关注

    获取到了2个节点的坐标参数A(X1,Y1),B(X2,Y2),用坐标参数值就可以计算A和B之间的距离。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 8月14日
  • 已采纳回答 8月6日
  • 创建了问题 8月6日

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法