Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8717531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:19:35+00:00 2026-06-13T06:19:35+00:00

I have a label-point on the line between two other points. Say its 20

  • 0

I have a label-point on the line between two other points. Say its 20 pixels in from the first point of the line.

Now i want to move the first point of the line, taking the label-point with me, so i move the first point and redraw the line to the last point of the line.
Works fine, but how do i move the label to the new line, putting it again 20px in from the left.

(the length 20px varies as a variable depending on where the label has been put on the line by a user).

I was thinking like using Y=kx+m cant get it right though…

This is what i’ve written so far:

-(double)positionOfLabel{
    //return relative position of label on old line, relatively the first point.
    return [self length]-   sqrt(self.label.center.x*self.label.center.x+self.label.center.y*self.label.center.y);
    //return [self length]-sqrt((self.last.x - self.label.center.x)*(self.last.x -  self.label.center.x) + (self.last.y - self.label.center.y)*(self.last.y -      self.label.center.y));
}

-(void)labelTranslate:(double)length{
    NSLog(@"Translating label length:%f", [self length]);
    double m= (self.last.y-self.first.y)/(self.last.x-self.first.x);
    double x= self.first.x+length/(sqrt(1+m*m));
    double y= x*m;
    NSLog(@"Moving label to:%f,%f", x,y);
    [self.label setCenter:CGPointMake(x, y)];


}

Position of label is meant as returning how far from the first point the label is placed.

Example of movement of the lines, and hence the two dots at the end of the line
image

As you can see in the image, an arrow represents a line consisting of first and last dot. the distance between the redpoint and the first dot is preserved during the movement/translation of the arrow. This is however not working using my algorithm

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:19:35+00:00Added an answer on June 13, 2026 at 6:19 am

    Use of Y=kx+m form is not a good idea (because of vertical lines), so parametric form is recommended:

    enter image description here

    Norm = Sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1)) // check for 0
    Dir_X = (X2 - X1) / Norm
    Dir_Y = (Y2 - Y1) / Norm
    Label_X = X1 + 20 * Dir_X
    Label_Y = Y1 + 20 * Dir_Y
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a label which would display strings from 0 ft to say 999
i have a label tag and i want to remove text between <label> </label>
I have a label which labels the line numbers based on the text on
I have a label in my form. I want this label to dynamically change
I have a figure including two lines (one horizontal line, and one parabolic curve),
I want to make a tool that can measure angles between two user defined
I have a horizontal line in a ggplot and I would like to label
I have contstructed a string in Rails: text = 'Example, first line\nExample, second line'
I have a Label that translates a code inserted by the user to the
I have a label that overlays on an MKMapView . The only problem is,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.