Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Getting Line Length

Contributor ,
Jun 25, 2013 Jun 25, 2013

Hi,

I need to be able to draw lines dynamically between several sets of 2 dragged/dropped points on stage.

If I draw a line dynamically between a set of 2 points (LineA), using graphics class, moveTo(point1.x, point1.y), lineTo (point2.x, Point2.y), and I want to then get LineA's length (length of the newly drawn line), plus LineA.x, LineA.y, would I simply use LineA.width, LineA.x, LineA.y?

I'm not sure how else to do this?

Any suggestions appreciated.

saratogacoach

TOPICS
ActionScript
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 25, 2013 Jun 25, 2013

if you want the distance between the centers, use the function in my last message and leave the dots' reg points in their centers.

Translate
Community Expert ,
Jun 25, 2013 Jun 25, 2013

use distanceF():

function distanceF(pt1:Point,pt2:Point):Number{

return Math.sqrt((pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y));

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 25, 2013 Jun 25, 2013

I think I didn't explain fully. While I used the term "points" what I meant was "dots." The user drags and drops two 6X6 dots on the stage, then dynamically draws a line between these 2 dots.

So a set of 2 dots (the beginning and end for the dynamically drawn line between them). Then need to get the length of the drawn line, maybe also its x, y.

Would I still use distanceF() ? Or some other way?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2013 Jun 25, 2013

use:

function distanceF(pt1:DisplayObject,pt2:DisplayObject):Number{

return Math.sqrt((pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y));

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 25, 2013 Jun 25, 2013

One clarification:

The dots being dragged/dropped are movieclips that I am creating with a center registration point. Should I instead create these with top left registration. My goal is to get an accurate measure of the distance between the centers of the 2 dots (line length drawn from center to center). So, I figured that center registration would be useful. But, if your above formula depends on a different registration point then I would need to change this.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2013 Jun 25, 2013

if you want the distance between the centers, use the function in my last message and leave the dots' reg points in their centers.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 25, 2013 Jun 25, 2013

Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2013 Jun 25, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines