CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2009
    Posts
    1,344

    Math: how move a line in same direction?

    heres a line:

    Origin:
    X0 = 0
    Y0 = 0
    Z0 = 0

    Destination:
    X1 = 100
    Y1 = 0
    Z1 = 500

    using the same direction, how can i move a line using Math?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,313

    Re: Math: how move a line in same direction?

    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2009
    Posts
    1,344

    Re: Math: how move a line in same direction?

    Victor i don't get notifications... can you see it please? is maybe because i'm login even not be here?
    i use the Hotmail mail.

    or i din't get the Translation or something is wrong
    what i mean is that i only need move the line in same direction, like just i line dot.
    i found 1 way(always with float types):
    1 - calculate the line distance;
    2 - calculate the X and Y distance;
    3 - divide the XDistance with LineDistance and the same for YDistance for get the XSteps and YSteps;
    4 - now i can add\sub the Steps for the next\previous line dot and with same orientation\angle:
    Move line back(same can be done on Z):
    Code:
    //Getting Line Distance(float results):
            float DX = abs(X1 - X0);
            float DY = abs(Y1 - Y0);
            float DZ = abs(Z1 - Z0);
            float LineDistance =abs( sqrt(pow(DX,2) + pow(DY,2) + pow(DZ,2)));
    
    //Getting the Steps incrementation(float results):
            float XSteps = DX/LineDistance;
            float YSteps = DY/LineDistance;
            float ZSteps = DZ/LineDistance;
    
    
    
    float NewX0 = X0 - XSteps;
    float  NewY0 = Y0 - YSteps;
    float  NewZ0 = Z0 - ZSteps;
    float NewX1 = X1 - XSteps;
    float NewY1 = Y1 - YSteps;
    float NewZ1 = Z1 - ZSteps;
    for move front we add the steps.
    but sometimes i fail on calculations... and i fail much more in using the 'int' instead 'float' on calculations
    Last edited by Cambalinho; November 13th, 2022 at 03:13 PM.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,313

    Re: Math: how move a line in same direction?

    Quote Originally Posted by Cambalinho View Post
    Victor i don't get notifications...
    Yes, it is a new bug in the forum's engine. The Admin promised that this bug will be fixed in some weeks...

    Quote Originally Posted by Cambalinho View Post
    or i din't get the Translation or something is wrong
    What "Translation" do you mean?

    Quote Originally Posted by Cambalinho View Post
    what i mean is that i only need move the line in same direction, like just i line dot.
    ...
    What do you mean by the "same direction"?
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 2009
    Posts
    1,344

    Re: Math: how move a line in same direction?

    see these line with origin and destinity: LineSteps line(0,200,0,400,200,500);
    now i need move the line... how can i subtract 1 from (0,200,0), but continue with same line size or (400,200,500) minus 1?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,313

    Re: Math: how move a line in same direction?

    Well, "subtract 1 from" something is easy. The only questio is in what direction are you going to move your line!
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2009
    Posts
    1,344

    Re: Math: how move a line in same direction?

    on line direction

  8. #8
    Join Date
    Apr 2009
    Posts
    1,344

    Re: Math: how move a line in same direction?

    hello. did i miss something?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured