How to know the real distance between nodes (in meters) ?

177 views
Skip to first unread message

Catrina Ivanova

unread,
Jun 18, 2022, 6:53:44 AM6/18/22
to ns-3-users
hello, 
I know how to get the position of the nodes coordinates (x, y, z) and how to calculate the distance between two nodes with this formula  : d=√((x_2-x_1)²+(y_2-y_1)²)

But is the distance found in in meters centimeters ? 


thank you

john kujk

unread,
Jun 18, 2022, 7:53:32 AM6/18/22
to ns-3-users
meters

Catrina Ivanova

unread,
Jun 19, 2022, 4:07:38 AM6/19/22
to ns-3-users
thank you

Ali H. Wheeb

unread,
Jun 20, 2022, 1:29:25 AM6/20/22
to ns-3-users
hi

I also use ns3 to simulate ad hoc networks and FANET. so, kindly, explain how you know the node's position?  and the distance between two nodes
for example node 1 and node 2?

best regards

Catrina Ivanova

unread,
Jun 27, 2022, 8:26:29 AM6/27/22
to ns-3-users
you can get the node position from the Mobility model like ths : 

Ptr<Node> node = m_ipv4->GetObject<Node> ();
Ptr<MobilityModel> mob = node->GetObject<MobilityModel>();
uint16_t x = mob->GetPosition().x;
uint16_t y = mob->GetPosition().y;
uint16_t z = mob->GetPosition().z;

Ali H. Wheeb

unread,
Jun 27, 2022, 9:13:15 AM6/27/22
to ns-3-...@googlegroups.com
Thanks for responding 

And how to know the distance between two nodes


--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/NxUmyns-bdQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/fba0e2e0-f917-4d68-974d-0d768e0819ffn%40googlegroups.com.

Tom Henderson

unread,
Jun 27, 2022, 1:28:52 PM6/27/22
to ns-3-...@googlegroups.com, Ali H. Wheeb
On 6/27/22 06:12, Ali H. Wheeb wrote:
> Thanks for responding
>
> And how to know the distance between two nodes
>

See the MobilityModel::GetDistanceFrom () method.

Ali H. Wheeb

unread,
Jul 1, 2022, 4:08:09 PM7/1/22
to ns-3-users
is there an example video or tutorial to understand

MobilityModel::GetDistanceFrom () method.

Geovany Teca

unread,
Jul 1, 2022, 4:24:38 PM7/1/22
to ns-3-...@googlegroups.com
Hi, 
Here is the API:
double
MobilityModel::GetDistanceFrom (Ptr<const MobilityModel> other) const
I am not sure if it is gonna work, but it is worth trying and you can improve, but here is a good starting point:
#include "mobility-model.h"

NodeContainer nodes ;
nodes.Create(2);
NodeContainer::Iterator firstNode = nodes.Begin();
Ptr<Node> NodePtr = *firstNode;
Ptr<MobilityModel> position = NodePtr->GetObject<MobilityModel> ();
double distance = GetDistanceFrom (position); /* print distance here */
This is just to give you an idea how you can call the method, try to adapt to your code.

Regards


--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/da032d49-28b8-4625-a1d1-c104412c0321n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages