Line scaling - how to get the new coordinates?
I am working on a application which involves line scaling. I am working in Java/GWT so if there is already something inbuilt it would be great. I know this is very basic maths but I can't get my head around it (not its not homework before you ask).
I know it can be done with Trig, but this is a piece of code that will be run 1000s of times so it needs to be basic operations if possible (- + / *)
Essentially the orange line scales up and produces t开发者_开发百科he blue line.
I have:
- Coordinates (x1, y1) & (x2, y2)
- Length of orange line (by Pythagoras)
- Length of blue line
I need:
- Coordinates (u1, v1) & (u2, v2)
You want to look into the equation of a straight line. With the magnitude and start point you can easily calculate the end point for a given length.
Y = mx + b
Here is a quick tutorial:
http://www.mathsisfun.com/equation_of_line.html
You could also google for collinear points which is actually what you are looking for.
Alternativly you could use vector maths:
http://www.netcomuk.co.uk/~jenolive/vect3.html
精彩评论