V
V
Valery Makarov2014-05-21 20:48:27
Mathematics
Valery Makarov, 2014-05-21 20:48:27

A segment rotates around a point that moves along it

The niece asked for help with solving a problem in Pascal, but I can’t figure out what sines to implement this through.
A point moves uniformly along a segment of length A from one end to the other. Display on the screen the rotation of this segment about this point.
Who will prompt the mathematical formula describing the given movement?
UPD. Huge thanks to @OLS and @iiil for suggesting correct solutions. I settled on the option with polar coordinates (simply because the most basic was implemented in Pascal).

program polar_rot;

uses graphabc;

const
  WindowWidth = 600; WindowHeight = 600;
  CenterX = 300; CenterY = 300;
  PI = 3.1415926;
  Count = 2000; Len = 290;
  r = 3; PenWidth = 3;

var
  Ro : real;
  Len1, Len2 : real;
  Time : integer;
  X1, Y1, X2, Y2 : integer;

begin

  SetWindowSize(WindowWidth, WindowHeight);
  SetPenWidth(PenWidth);

  for Time := 0 to Count do
  begin
  
    Ro := Time / Count * 2 * PI;
    Len1 := Len * (Time / Count);
    X1 := CenterX + round(Len1 * cos(Ro));
    Y1 := CenterY + round(Len1 * sin(Ro));
    Len2 := Len - Len1;
    X2 := CenterX - round(Len2 * cos(Ro));
    Y2 := CenterY - round(Len2 * sin(Ro));
    
    LockDrawing;
    ClearWindow(clWhite);
    SetPenColor(clBlue);
    Line(X1, Y1, X2, Y2);
    SetPenColor(clRed);
    Circle(CenterX, CenterY, r);
    Redraw;

  end;

end.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2014-05-21
@valemak

It seems to me that this is easiest to solve in polar coordinates.
The point, if I understood the condition correctly, is generally fixed on the screen - for example, in the center - and a segment rotates around it.
In this case, the angle RO of the polar coordinates changes linearly in time,
the lengths of the "tails" of the segment from different sides of the point also change linearly in time.
As a result, we have something like:

iCnt:=300; fLen:=200;
for iTime:=0 to iCnt-1 do
    begin
    fRo:=iTime/iCnt*2*PI;
    fLen1:=fLen*(iTime/iCnt);
    iX1:=iXCenter+round(fLen1*cos(fRo));
    iY1:=iYCenter+round(fLen1*sin(fRo));
    fLen2:=fLen-fLen1;
    iX2:=iXCenter-round(fLen2*cos(fRo));
    iY2:=iYCenter-round(fLen2*sin(fRo));
    // отрисовка
    end;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question