makeLine w/ center coord rather than x1,y1,x2,y2?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

makeLine w/ center coord rather than x1,y1,x2,y2?

Barton, Robert
Hi everyone,

I'm guessing this will be a quick "No", but I figured I'd try asking
anyways...

When writing a macro, is it possible to draw a line based upon the center
point of that line?  IOW, rather than using makeLine(156,197,356,197),
could I create a line by specifying the center point (256,197 in this case)
and then specifying how long the line should be?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: makeLine w/ center coord rather than x1,y1,x2,y2?

dscho
Hi,

On Tue, 17 Jul 2007, Robert Barton wrote:

> When writing a macro, is it possible to draw a line based upon the
> center point of that line?  IOW, rather than using
> makeLine(156,197,356,197), could I create a line by specifying the
> center point (256,197 in this case) and then specifying how long the
> line should be?

First, you'd need the angle, too.  Second, it is easy to write a (macro)
function which does that:

-- snip --
function makeLine2(centerX, centerY, length, angle)
{
        angle = -angle * PI / 180;
        dX = cos(angle) * length / 2;
        dY = sin(angle) * length / 2;

        makeLine(centerX - dX, centerY - dY, centerX + dX, centerY + dY);
}
-- snap --

Ciao,
Dscho
Reply | Threaded
Open this post in threaded view
|

Re: makeLine w/ center coord rather than x1,y1,x2,y2?

ctrueden
In reply to this post by Barton, Robert
Hi Robert,

The center point of the line together with the line length is
insufficient information to draw it -- you are missing the slope.
However, it should be quite to do some quick math (point slope
formula) on center point + slope + length to obtain the (x1,y1) and
(x2,y2) coordinates required to call drawLine.

-Curtis

On 7/17/07, Robert Barton <[hidden email]> wrote:

> Hi everyone,
>
> I'm guessing this will be a quick "No", but I figured I'd try asking
> anyways...
>
> When writing a macro, is it possible to draw a line based upon the center
> point of that line?  IOW, rather than using makeLine(156,197,356,197),
> could I create a line by specifying the center point (256,197 in this case)
> and then specifying how long the line should be?
>
> Thanks.
>
Reply | Threaded
Open this post in threaded view
|

Re: makeLine w/ center coord rather than x1,y1,x2,y2?

lechristophe
In reply to this post by Barton, Robert
Hi Robert,

You would also have to specify an angle, because just the center point
and the length will not define a unique line. If you specify these four
parameters : the center, the length and an angle (relative to a
reference), you can easily use them to compute the four coordinates of
the end points.

A : the angle relative to the horizontal direction
x0, y0 : coordinates of the center
L : length of the segment

then the coordinates of the end points (x1,y1 and x2,y2) are

x1 = x0-0.5*L*cosA
y1 = y0-0.5*L*sinA

x2 = x0+0.5*L*cosA
y2 = y2+0.5*L*sinA

or something like that ;)

Cheers

Christophe


Christophe

Robert Barton a écrit :

> Hi everyone,
>
> I'm guessing this will be a quick "No", but I figured I'd try asking
> anyways...
>
> When writing a macro, is it possible to draw a line based upon the center
> point of that line?  IOW, rather than using makeLine(156,197,356,197),
> could I create a line by specifying the center point (256,197 in this case)
> and then specifying how long the line should be?
>
> Thanks.
>