ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* METAPOST -- specifying an unknown point coordinate by giving the angle from another known point
@ 2010-02-26  1:18 James Fisher
  2010-02-26  1:41 ` Troy Henderson
  2010-02-26 21:42 ` Nicola
  0 siblings, 2 replies; 7+ messages in thread
From: James Fisher @ 2010-02-26  1:18 UTC (permalink / raw)
  To: mailing list for ConTeXt users

This isn't specifically a ConTeXt question, but via it I've run into a
seemingly simple problem in METAPOST that I just can't solve.  I'm
trying to draw a parallelogram by specifying: (1) the length of sides
parallel to the x-axis; (2) the total height of the figure; (3) one of
the interior angles.  This is how I'm trying to solve it:

-----------------

% Draw a parallelogram, like so:
%
%         z3    z2
%         +-----+   ^
%        /     /    |
%       /     /     |
%      /     /      |10 units
%     /BL   /       |
%    +-----+        v
%   z0     z1
%    <----->
%    5 units
%
%    Interior angle BL = 87 degrees


beginfig(1);

  z0 = origin;        % bottom left
  z1 = (5,0);         % bottom right
  y2 = y3 = 10;       % shape is 10 units high
  x2 - x3 = x1 - x0;  % top edge is the same length as bottom edge

  % We've completely specified z0 and z1;
  % We know that the top edge is the same length and angle as the
bottom, but lies somewhere on y = 10;
  % all we have to do is specify one angle and we have a complete parallelogram.
  %
  % The following should work as it provides the following information:
  % the unit vector from z0 to z3 is at an angle 87 degrees
anticlockwise from (0,0) -- (1,0).

  angle(z3-z0) = dir(87);

endfig;
end;

--------------------

This doesn't work; using the angle() function gives the error:

   Not implemented: angle(unknown pair).

Strictly speaking, yes, z3 has an unknown x-coordinate at that time in
execution.  But I am told that METAPOST is declarative, so I would
expect my line of code to mean: "set the x-coordinate of z3 such that
angle(z3-z0) = dir(87)".  AFAICS that provides all the needed
information to draw the shape.

So, is there another way I can do what I want without falling into
low-level trig?



Best,


James
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: METAPOST -- specifying an unknown point coordinate by giving the angle from another known point
  2010-02-26  1:18 METAPOST -- specifying an unknown point coordinate by giving the angle from another known point James Fisher
@ 2010-02-26  1:41 ` Troy Henderson
  2010-02-26  1:44   ` Troy Henderson
  2010-02-26 21:42 ` Nicola
  1 sibling, 1 reply; 7+ messages in thread
From: Troy Henderson @ 2010-02-26  1:41 UTC (permalink / raw)
  To: mailing list for ConTeXt users

James,

Try this:

z0 = origin;
z1 = (5,0);
z3 = 10*dir(87);
z2 = z3-z0+z1;

Troy Henderson
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: METAPOST -- specifying an unknown point coordinate by giving the angle from another known point
  2010-02-26  1:41 ` Troy Henderson
@ 2010-02-26  1:44   ` Troy Henderson
  2010-02-26  2:14     ` James Fisher
  0 siblings, 1 reply; 7+ messages in thread
From: Troy Henderson @ 2010-02-26  1:44 UTC (permalink / raw)
  To: mailing list for ConTeXt users

James,

I apologize, but the previous information that I gave you was wrong.
Try this instead:

z0 = origin;
z1 = (5,0);
BL:=87;
r:=10/sind(BL);
z3 = r*dir(BL);
z2 = z3-z0+z1;

Troy
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: METAPOST -- specifying an unknown point coordinate by giving the angle from another known point
  2010-02-26  1:44   ` Troy Henderson
@ 2010-02-26  2:14     ` James Fisher
  2010-02-26  3:29       ` Troy Henderson
  0 siblings, 1 reply; 7+ messages in thread
From: James Fisher @ 2010-02-26  2:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Aha!  That certainly works.  I suspected I would have to fall back on
"low-level" trig :).  Many thanks!

On Fri, Feb 26, 2010 at 1:44 AM, Troy Henderson <thenders@gmail.com> wrote:
> James,
>
> I apologize, but the previous information that I gave you was wrong.
> Try this instead:
>
> z0 = origin;
> z1 = (5,0);
> BL:=87;
> r:=10/sind(BL);
> z3 = r*dir(BL);
> z2 = z3-z0+z1;
>
> Troy
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
>
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: METAPOST -- specifying an unknown point coordinate by giving the angle from another known point
  2010-02-26  2:14     ` James Fisher
@ 2010-02-26  3:29       ` Troy Henderson
  0 siblings, 0 replies; 7+ messages in thread
From: Troy Henderson @ 2010-02-26  3:29 UTC (permalink / raw)
  To: mailing list for ConTeXt users

James,

How about this.

BL:=87;
z0=origin;
z1=(5,0);
z4=dir(BL); % Intermediate point
z3=10/y4*z4;
z2=z3+z1;

or alternatively without having to define z4


BL:=87;
z0=origin;
z1=(5,0);
z3=10/(ypart dir(BL))*dir(BL);
z2=z3+z1;
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: METAPOST -- specifying an unknown point coordinate by giving the angle from another known point
  2010-02-26  1:18 METAPOST -- specifying an unknown point coordinate by giving the angle from another known point James Fisher
  2010-02-26  1:41 ` Troy Henderson
@ 2010-02-26 21:42 ` Nicola
  2010-02-28  0:37   ` James Fisher
  1 sibling, 1 reply; 7+ messages in thread
From: Nicola @ 2010-02-26 21:42 UTC (permalink / raw)
  To: ntg-context

In article 
<771da05a1002251718l55669a0co770b5a78bed84e4b@mail.gmail.com>,
 James Fisher <jameshfisher@gmail.com> wrote:

> This isn't specifically a ConTeXt question, but via it I've run into a
> seemingly simple problem in METAPOST that I just can't solve.  I'm
> trying to draw a parallelogram by specifying: (1) the length of sides
> parallel to the x-axis; (2) the total height of the figure; (3) one of
> the interior angles. 

Curiously enough, nobody has posted a solution that uses 'whatever', so 
here it is:

z0 = origin;        % bottom left
z1 = (5,0);         % bottom right
y3 = y2 = 10;
z3 = z0 + whatever*dir(87); % z3 is obtained by starting at z0 and
                            % moving along dir(87)
z2-z1 = whatever*(z3-z0);   % The line z1--z2 is parallel to z0--z3

That is, what you were trying to achieve:

angle(z3-z0) = dir(87);

can be written instead:

z3 - z0 = whatever*dir(87);

Nicola

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: METAPOST -- specifying an unknown point coordinate by giving the angle from another known point
  2010-02-26 21:42 ` Nicola
@ 2010-02-28  0:37   ` James Fisher
  0 siblings, 0 replies; 7+ messages in thread
From: James Fisher @ 2010-02-28  0:37 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Ah, lovely!  Who knew there would be so many different solutions?  I'm
going to use Nicola's solution on this occasion, as it fits my thought
process best -- but thanks to Troy as your solutions showed me some
other things I didn't know.

All the best,

James

On Fri, Feb 26, 2010 at 9:42 PM, Nicola <nvitacolonna@gmail.com> wrote:
> In article
> <771da05a1002251718l55669a0co770b5a78bed84e4b@mail.gmail.com>,
>  James Fisher <jameshfisher@gmail.com> wrote:
>
>> This isn't specifically a ConTeXt question, but via it I've run into a
>> seemingly simple problem in METAPOST that I just can't solve.  I'm
>> trying to draw a parallelogram by specifying: (1) the length of sides
>> parallel to the x-axis; (2) the total height of the figure; (3) one of
>> the interior angles.
>
> Curiously enough, nobody has posted a solution that uses 'whatever', so
> here it is:
>
> z0 = origin;        % bottom left
> z1 = (5,0);         % bottom right
> y3 = y2 = 10;
> z3 = z0 + whatever*dir(87); % z3 is obtained by starting at z0 and
>                            % moving along dir(87)
> z2-z1 = whatever*(z3-z0);   % The line z1--z2 is parallel to z0--z3
>
> That is, what you were trying to achieve:
>
> angle(z3-z0) = dir(87);
>
> can be written instead:
>
> z3 - z0 = whatever*dir(87);
>
> Nicola
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
>
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-02-28  0:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-26  1:18 METAPOST -- specifying an unknown point coordinate by giving the angle from another known point James Fisher
2010-02-26  1:41 ` Troy Henderson
2010-02-26  1:44   ` Troy Henderson
2010-02-26  2:14     ` James Fisher
2010-02-26  3:29       ` Troy Henderson
2010-02-26 21:42 ` Nicola
2010-02-28  0:37   ` James Fisher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).