Hello, friends.
I want to access node coordinates in C++ and node coordinates are initially
defined in Otcl.
I referenced these two articles on accessing node coordinates in C++:
http://getch.wordpress.com/2011/02/10/finding-node-positionvelocity-and-speed-in-ns2-34/
http://getch.wordpress.com/2011/02/08/obtaining-node-position-and-energy-dynamically-in-ns2/
my .cc file is like this:
double x,y,z;
MobileNode *iNode = (MobileNode*)(Node::get_node_by_address(1));
iNode->getLoc(&x,&y,&z);
cout << "node1:" << x << " " << y << " " << z << endl;
And my tcl script is defined like this:
set val(nn) 11 ;#num of nodes
set val(xLimit) 100
set val(yLimit) 100
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns node]
$node_($i) set X_ [expr {$val(xLimit)*rand()}]
$node_($i) set Y_ [expr {$val(yLimit)*rand()}]
$node_($i) set Z_ 0.0
}
I expect that coordinates of node_(1) defined in my tcl script should be
print out, however, the result is:
node1:7.62437e-316 7.62415e-316 1.3793e-312
So I am curious that why do these coordinates so small, is there
anything wrong in my code?(I also searched the NS mail list, the code
snippet is similar)
Here is the part of coordinates in the nam trace file:
n -t * -a 8 -s 8 -S UP -v circle -c black -i black -x 20.682385433783001
-y 8.8519855909291589 -Z 0.0
n -t * -a 4 -s 4 -S UP -v circle -c black -i black -x 69.835971468051881
-y 33.172463547984357 -Z 0.0
n -t * -a 0 -s 0 -S UP -v circle -c black -i black -x 84.052622403974013
-y 72.424743591074247 -Z 0.0
n -t * -a 10 -s 10 -S UP -v circle -c black -i black -x
65.31614762047127 -y 68.493057260519379 -Z 0.0
n -t * -a 9 -s 9 -S UP -v circle -c black -i black -x 75.321826746371485
-y 33.942126265700033 -Z 0.0
n -t * -a 5 -s 5 -S UP -v circle -c black -i black -x 29.594850973037467
-y 0.66030384072116755 -Z 0.0
n -t * -a 1 -s 1 -S UP -v circle -c black -i black -x 42.665535184864666
-y 79.649852020502948 -Z 0.0
n -t * -a 6 -s 6 -S UP -v circle -c black -i black -x 97.726651000663011
-y 91.823368143208029 -Z 0.0
n -t * -a 2 -s 2 -S UP -v circle -c black -i black -x 75.062908593128867
-y 82.3047247167233 -Z 0.0
n -t * -a 7 -s 7 -S UP -v circle -c black -i black -x 75.348382897371607
-y 80.271356124557258 -Z 0.0
n -t * -a 3 -s 3 -S UP -v circle -c black -i black -x 95.508313968548691
-y 8.232869397957284 -Z 0.0
So I want to know that why does the coordinates accessed by
get_node_by_address() function is not the same as those in nam trace file or
in the nam GUI ?
Thank you very much, any suggestions is appreciated.
--
Su Jinzhao