Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.