Jump to content

line between two points


alin19

Recommended Posts

for ($j=1; $j<$100;$j+=0.01)

{

    $z=470-2*$j;

$x=50+$j;

  imagesetpixel($img,$x, $z,$black);

}

 

 

 

i have this script to draw a line from one point with a known lenght;

 

 

but how can i drow a line between point a(10;20)    and b(30;50)

 

just an example please

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/87259-line-between-two-points/
Share on other sites

Well, you could try to incorporate some geometry to find the equation of the line (Y= MX + B). But, that would make the solution rather complex.

 

Here is the approach I would take. You know that the line was a width (X) of 20 units. And in that space the height (Y) changes 30 units. So, the slope if the line would be 30/20 or 1.5. So for any X position, the Y position would be 20 + (1.5 * (X-10)) Where 20 is the starting Y position and 10 is the starting X position.

 

So, just create a loop to iterate through each X coordinate and compute the Y coordinate.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.