android - Find out the coordinates using slope and start point -


i trying achieve task resize line after taking length input user.so have old length,old points(p1 ,p2) , have find new p2 after taking new length user.i here pasting code have tried resize line using slope not working.i totally new in canvas part kind of search hint appreciable.thanks in advance.

method find out angle between previous points:

public double calculateangle(){   if(selectedshape!=null){         innwall shape  = (innwall)selectedshape;     if(shape!=null)     return calangle(shape.y2-shape.y1, shape.x2-shape.x1);   } return -1; } 

method find out coordinates

public void calcoordinates(double length){          innwall shape  = (innwall)selectedshape;         if(shape!=null){             double angle = calculateangle();         log.e(tag, "cal angle"+(int)calculateangle());         log.e(tag, "cal length"+(int)length);         log.e(tag, "x coodinatee"+shape.x1+length*math.cos(angle));         log.e(tag, "y coodinatee"+shape.y1+length*math.sin(angle));         shape.x2=(float)(shape.x1+length*math.cos(angle));         shape.y2=(float)(shape.y1+length*math.sin(angle));  }  private  double calangle(double dy,double dx){         return double compassbearing=dy/dx; } 

double scale = old_length/new_length; dx = p2.x - p1.x dy = p2.y - p1.y 

you know that:

 - scale_x^2 + scale_y^2 = scale^2  - scale_x/scale_y = dx/dy 

thus:

scale_y = sqrt(scale * scale * dy *dy/(dx*dx + dy*dy)); scale_x = scale_y*dx/dy; 

if relative point p1 p2.x += (p2.x-p1.x) * scale_x p2.y += (p2.y-p1.y) * scale_y

in theory, scaling need multiply points scaling matrix in case 2d.

[ 1  0  dx ] [ p1.x ]    [ p2.x ] [ 0  1  dy ] [ p1.y ]  = [ p2.y ] [ 0  0  1  ] [ 1    ]    [ 1  ] 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -