Home   Help Search Login Register  

Author Topic: Marker and a little Math  (Read 1086 times)

0 Members and 1 Guest are viewing this topic.

Offline Eymerich

  • Members
  • *
Marker and a little Math
« on: 04 Jun 2007, 10:25:16 »
Given 2 point in a 2d space (2 marker coords)
I need a coord which is in middle distance of them and with the direction of c pointing to B.


                              B.
             
               C.
 
 A.

or

  A.               C. (--->)                B.


In other words:

Userc can choose on the map the waypoint to give to his units. Every  "click" on map creates a wp on the map itself.
I'd like to put a marker (arrow) beetwen A e B (marker coords = C) "pointing" to b.
Is there a smart way to do this?

Regards

 :)
« Last Edit: 04 Jun 2007, 10:29:24 by Eymerich »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Marker and a little Math
« Reply #1 on: 04 Jun 2007, 10:30:05 »
_distance = sqrt(((getMarkerPos "mk_2" select 0)-(getMarkerPos "mk_1" select 0))^2+((getMarkerPos "mk_2" select 1)-(getMarkerPos "mk_1" select 1))^2);
_ang = ((getMarkerPos "mk_2" select 0)-(getMarkerPos "mk_1" select 0)) atan2 ((getMarkerPos "mk_2" select 1)-(getMarkerPos "mk_1" select 1));
_middle_x = (getMarkerPos "mk_1" select 0)+sin(_ang)*_distance/2;
_middle_y = (getMarkerPos "mk_1" select 1)+cos(_ang)*_distance/2;
_middle = [_middle_x, _middle_y];

Offline Eymerich

  • Members
  • *
Re: Marker and a little Math
« Reply #2 on: 04 Jun 2007, 10:31:32 »
Wow!

Thanks for the fastest answer!

 :good: