The Daily Click ::. Forums ::. Klik Coding Help ::. Connecting two Points?
 

Post Reply  Post Oekaki 
 

Posted By Message

Battenburg



Registered
  24/04/2009
Points
  13
19th July, 2009 at 17:23:25 -

Anyone got any idea on how to create a line between two coordinates? Lets say an object drops dots, how can I create lines between? I can think of some small ways to cheat through this but none seem satisfactory...

All/Any help much appreciated

 
n/a

Spitznagl

Cabinetmaker

Registered
  06/12/2008
Points
  4260

The SpinsterVIP MemberHas Donated, Thank You!Picture Me This Round 29 Winner!Picture Me This Round 31 Winner!Picture Me This Round 36 Winner!
19th July, 2009 at 17:46:30 -

http://www.mediafire.com/file/ztmmmvzduyy/
Just adapt it to your needs.

 
...

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1960

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
19th July, 2009 at 17:52:51 -

Create an active object for the line, 100 pixels wide, and <line thickness> high. Set it's hotspot to the center-left position.

+ Whenever...
> Set Line position at 0,0 from Point A
> Set Line angle to 0
> Set Line scale to Sqr(((X("Point A")-X("Point B")) pow 2) + ((X("Point A")-X("Point B")) pow 2)) / 100
> Set Line angle to ATan2(Y( "Point A" )-Y( "Point B" ), X( "Point B" )-X( "Point A" ))

 
n/a

Battenburg



Registered
  24/04/2009
Points
  13
19th July, 2009 at 18:22:55 -

Thank you very much!

I've been toying with it for a good while but I don't suppose you could spare a little explanation? I'm not good on my maths these days...

only if you don't mind.

EDIT- Thanks to you too sketchy. Just noticed that post sneaked in 4 seconds after I posted. I'll go toy with that too.

Edited by Battenburg

 
n/a

Spitznagl

Cabinetmaker

Registered
  06/12/2008
Points
  4260

The SpinsterVIP MemberHas Donated, Thank You!Picture Me This Round 29 Winner!Picture Me This Round 31 Winner!Picture Me This Round 36 Winner!
19th July, 2009 at 19:23:19 -

I don't mind answering your questions, but I'm not a good teacher.

This is simple trigonometry. Using the pythagore formula, the "scale" event finds the lenght of the hypothenuse of an imaginary right-angled triangle which has one side long as the X distance between the two objects, and another side long as the Y distance between the same objects. Then, it streches the line object to that lenght.

Once streched, one end of the line should be on the object(if you set the line's hotspot to the left end of the image) and you just need to rotate it. ATan2 finds the right angle.

BTW, both Sketchy's suggestions and mine are the same. Only difference: intead of a 1pxl wide line object, he starts with a 100 pxls long line. The results should be the same.

Edited by Spitznagl

 
...

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1960

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
19th July, 2009 at 21:10:27 -

Yeah, they're exactly the same.
I wouldn't have bothered posting it, except that I started typing my reply before Spitznagl had posted his.

 
n/a

Battenburg



Registered
  24/04/2009
Points
  13
21st July, 2009 at 00:45:56 -

Stupid ol' me. Been toying around and done a bit of light studies. All the length formula works fine but I can't seem to get the angle right. Even after I found that darn Arc Tangent (Kept on writing in "Atan2" rather than "Atan(2)", Blarglewargle!-_-) it doesn't want to sit itself nicely on the "cursor" object.

Or am I doing something stupid again.... ?

 
n/a

Spitznagl

Cabinetmaker

Registered
  06/12/2008
Points
  4260

The SpinsterVIP MemberHas Donated, Thank You!Picture Me This Round 29 Winner!Picture Me This Round 31 Winner!Picture Me This Round 36 Winner!
21st July, 2009 at 00:59:45 -

It's ATan2(X,Y)

If you need to flip the line horizonataly or verticaly, just change, let's say; Y(active1)-Y(active2) for Y(active2)-Y(active1)


 
...

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1960

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
21st July, 2009 at 02:31:26 -

No, it's ATan2(Y,X)

The "Y" comes first.
Like Spitznagl says, you need to flip the Y axis (as 0 is the top of the screen), so the expression is kind of like:
ATan2( Ay - By, Bx - Ax )

Are you using HWA? I'm not certain it's been added to the HWA version of MMF2 yet.
In the expression evaluator it should be listed under:

special -> sine & cosine -> arc tangent of y/x

If it's not there you'll have to use the Advanced Direction extension to find the angle instead.


 
n/a

-J-



Registered
  05/10/2008
Points
  228

VIP MemberThe Cake is a Lie
21st July, 2009 at 14:03:27 -

"I'm not certain it's been added to the HWA version of MMF2 yet."

That caused me about an hour of grief once... until I noticed I'd clicked the wrong MMF2 icon.

 
n/a ...
   

Post Reply



 



Advertisement

Worth A Click