CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Math: how move a line in same direction?

1. Senior Member 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?  Reply With Quote

2. ## Re: Math: how move a line in same direction?  Reply With Quote

3. Senior Member 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.  Reply With Quote

4. ## Re: Math: how move a line in same direction? Originally Posted by Cambalinho Yes, it is a new bug in the forum's engine. The Admin promised that this bug will be fixed in some weeks...  Originally Posted by Cambalinho or i din't get the Translation or something is wrong What "Translation" do you mean? Originally Posted by Cambalinho 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"?  Reply With Quote

5. Senior Member 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?  Reply With Quote

6. ## 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!  Reply With Quote

7. Senior Member Join Date
Apr 2009
Posts
1,344

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

on line direction  Reply With Quote

8. Senior Member Join Date
Apr 2009
Posts
1,344

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

hello. did i miss something?  Reply With Quote

#### Posting Permissions

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