screen possition
Altair Forum User
Altair Employee
Answers
-
Hi
To clarify the question, I want to return the screen (pixel) coordinates of a node/element in the current screen view?
0 -
Hi there
I think this is similar to my question:
Retrieving Screen Coords of a Node
Maybe one should call the support to get an answer ...
Greetings
Thomas
0 -
Called the support - got no answer - but a colleague at work found out ...
Here is the solution:
# getScreenPosOfNode --## Delivers the screen position of a node $nodeID. A node at the lower left# corner of the viewport gives (0/0) - at the upper right corner (1/1).## Arguments:# nodeID node number to retrieve screen position for## Results:# Returns a list of 2 values: relative x- and relative y-screen-positionproc getScreenPosOfNode {nodeID} { set P [join [hm_nodevalue $nodeID]] ;# real world coords in global coord sys set view [join [hm_getcurrentview]] # extract transformation matrix T set T [list [lrange $view 0 2] [lrange $view 4 6] [lrange $view 8 10]] set v [lrange $view 12 14] ;# translation vector v foreach {minx miny maxx maxy} [join [hm_getviewport]] {} # rotational transformation: real world coords to screen coords (P-->P_) set P_ {} for {set row 0} {$row < 3} {incr row} { set coord_ 0 for {set col 0} {$col < 3} {incr col} { set coord_ [expr {$coord_+[lindex $T $col $row]*[lindex $P $col]}] } lappend P_ $coord_ } # add translation (P_-->P_canvas) set Px_canvas [expr {[lindex $P_ 0]+[lindex $v 0]}] set Py_canvas [expr {[lindex $P_ 1]+[lindex $v 1]}] # compute relative screen position set Canvas_DeltaX [expr {$maxx-$minx}] set Canvas_DeltaY [expr {$maxy-$miny}] set P_relX [expr {($Px_canvas-$minx)/double($Canvas_DeltaX)}] set P_relY [expr {($Py_canvas-$miny)/double($Canvas_DeltaY)}] return [list $P_relX $P_relY]}
0