2017-07-07 6 views
-2

Ich möchte eine Sternmarkierung entlang der Sechseck-Trajektorie verschieben, die der "Kreis-Trajektorie" ähnelt, die ich am Ende meiner Frage hinzugefügt habe. Vielen Dank.Eine Sternmarkierung entlang einer Sechseckbahn bewegen?

Dies ist der Quellcode, dass ich noch für die Erstellung von konzentrischen hegzagons geschrieben, aber ich weiß nicht, wie ein Stern Marker zu bewegen, die die konzentrischen Hexagone überquert, ich einen ähnlichen Simulationscode für Kreisbahn geschrieben hatte, aber Ich konnte es nicht für Hexagon tun.

%clc; % Clear the command window. 
%close all; % Close all figures (except those of imtool.) 
%clear; % Erase all existing variables. Or clearvars if you want. 
workspace; % Make sure the workspace panel is showing. 
format long g; 
format compact; 
fontSize = 20; 
angles = linspace(0, 360, 7); 
radii = [20, 35, 50,70]; 
% First create and draw the hexagons. 
numberOfHexagons = 4; 
% Define x and y arrays. Each row is one hexagon. 
% Columns are the vertices. 

x1=radii(1) * cosd(angles)+50; 
y1 = radii(1) * sind(angles)+50; 
x2=radii(2) * cosd(angles)+50; 
y2 = radii(2) * sind(angles)+50; 
x3=radii(3) * cosd(angles)+50; 
y3 = radii(3) * sind(angles)+50; 
x4=radii(4) * cosd(angles)+50; 
y4 = radii(4) * sind(angles)+50; 
    plot(x1 , y1, 'b'); 
    hold on 
     plot(x2, y2, 'b'); 
     hold on 
     plot(x3, y3, 'b'); 
     hold on 
     plot(x4, y4, 'b'); 
     hold on 
     % Connecting Line: 
plot([70 100], [50 50],'color','b') 
    axis([0 100 0 100]) 
    hold on 

Kreisbahn:

% Initialization steps. 
format long g; 
format compact; 
fontSize = 20; 
r1 = 50; 
r2 = 35; 
r3= 20; 
xc = 50; 
yc = 50; 
% Since arclength = radius * (angle in radians), 
% (angle in radians) = arclength/radius = 5/radius. 
deltaAngle1 = 5/r1; 
deltaAngle2 = 5/r2; 
deltaAngle3 = 5/r3; 
theta1 = 0 : deltaAngle1 : (2 * pi); 
theta2 = 0 : deltaAngle2 : (2 * pi); 
theta3 = 0 : deltaAngle3 : (2 * pi); 
x1 = r1*cos(theta1) + xc; 
y1 = r1*sin(theta1) + yc; 
x2 = r2*cos(theta2) + xc; 
y2 = r2*sin(theta2) + yc; 
x3 = r3*cos(theta3) + xc; 
y3 = r3*sin(theta3) + yc; 
plot(x1,y1,'color',[1 0.5 0]) 
hold on 
plot(x2,y2,'color',[1 0.5 0]) 
hold on 
plot(x3,y3,'color',[1 0.5 0]) 
hold on 

% Connecting Line: 
plot([70 100], [50 50],'color',[1 0.5 0]) 
% Set up figure properties: 
% Enlarge figure to full screen. 
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0, 1, 1]); 
drawnow; 
axis square; 
for i = 1 : length(theta1) 
    plot(x1(i),y1(i),'r*') 
    pause(0.1) 
end 
for i = 1 : length(theta2) 
    plot(x2(i),y2(i),'r*') 
    pause(0.1) 
end 
for i = 1 : length(theta3) 
    plot(x3(i),y3(i),'r*')  
    pause(0.1) 
end 
+2

Was ist Ihre Frage? – excaza

+1

[Warum kann "Kann mir jemand helfen?" Keine eigentliche Frage?] (Http://meta.stackoverflow.com/q/284236) Außerdem, kassieren Sie Ihren Code von Teil A und bitten Sie uns, Teil B zu schreiben, ohne dass Sie zeigen Jede Anstrengung oder Forschung zu Teil B wird hier nicht sehr geschätzt. – Adriaan

+0

Vielen Dank für Ihren Kommentar, aber ich habe wirklich versucht, es selbst zu tun, aber leider konnte ich nicht und ich hatte keine andere Wahl, als meine Frage hier zu stellen, außerdem habe ich den Teil A nicht gestellt, um Sie zu bitten, Teil B zu schreiben. Wenn du meine Frage sorgfältig liest, würdest du wissen, dass ich Teil B geschrieben habe, um eine Kreisbahn zu zeichnen, in der ein roter Sternmarker konzentrische Kreise durchquert und jetzt Code schreiben möchte, der die gleiche Situation für die Sechseck-Trajektorie schafft, aber ich habe Probleme damit Code und ich habe Code geschrieben, der nur konzentrische Sechsecke erstellt. – zein

Antwort

0

würde ich Ihr Problem mit Parameterfunktion für die Trajektorie verallgemeinern. Darin Dreh Kernel verwenden, die Sie hier einige Beispiele in C++/VCL/GDI (sorry ich bin nicht Matlab freundlich, aber die Gleichungen sollten gleich in Matlab sein) für Kreis, Quadrat und Sechseck Drehkerne:

void getpnt_circle(double &x,double &y,double &pi2,double r,double t) // (x,y) = circle(r,t) t=<0,1> 
    { 
    pi2=2.0*M_PI; // circumference(r=1) 6.283185307179586476925286766559 
    t*=pi2; 
    x=r*cos(t); 
    y=r*sin(t); 
    } 
//--------------------------------------------------------------------------- 
void getpnt_square(double &x,double &y,double &pi2,double r,double t) // (x,y) = square(r,t) t=<0,1> 
    { 
    pi2=8.0;  // circumference(r=1) 
    // kernel 
    const int n=4;        // sides 
    const double x0[n]={+1.0,+1.0,-1.0,-1.0}; // side start point 
    const double y0[n]={-1.0,+1.0,+1.0,-1.0}; 
    const double dx[n]={ 0.0,-2.0, 0.0,+2.0}; // side tangent 
    const double dy[n]={+2.0, 0.0,-2.0, 0.0}; 

    int ix; 
    t-=floor(t); // t = <0, 1.0) 
    t*=n;   // t = <0,n) 
    ix=floor(t); // side of square 
    t-=ix;   // distance from side start 

    x=r*(x0[ix]+t*dx[ix]); 
    y=r*(y0[ix]+t*dy[ix]); 
    } 
//--------------------------------------------------------------------------- 
void getpnt_hexagon(double &x,double &y,double &pi2,double r,double t) // (x,y) = square(r,t) t=<0,1> 
    { 
    pi2=6.0;  // circumference(r=1) 
    // kernel 
    const int n=6;          // sides 
    const double c60=cos(60.0*M_PI/180.0); 
    const double s60=sin(60.0*M_PI/180.0); 
    const double x0[n]={+1.0,+c60,-c60,-1.0,-c60,+c60}; // side start point 
    const double y0[n]={ 0.0,+s60,+s60, 0.0,-s60,-s60}; 
    const double dx[n]={-c60,-1.0,-c60,+c60,+1.0,+c60}; // side tangent 
    const double dy[n]={+s60, 0.0,-s60,-s60, 0.0,+s60}; 

    int ix; 
    t-=floor(t); // t = <0, 1.0) 
    t*=n;   // t = <0,n) 
    ix=floor(t); // side of square 
    t-=ix;   // distance from side start 

    x=r*(x0[ix]+t*dx[ix]); 
    y=r*(y0[ix]+t*dy[ix]); 
    } 
//--------------------------------------------------------------------------- 
void TMain::draw() 
    { 
    if (!_redraw) return; 

    // clear buffer 
    bmp->Canvas->Brush->Color=clBlack; 
    bmp->Canvas->FillRect(TRect(0,0,xs,ys)); 

    int e; 
    double r,t,x,y,c,dr=15.0,dl=15.0; 
    int xx,yy,rr=3; 
    bmp->Canvas->MoveTo(xs2,ys2); 
    bmp->Canvas->Pen->Color=clAqua; 
    bmp->Canvas->Brush->Color=clBlue; 
    for (r=dr,t=0.0;;) 
     { 
     // get point from selected kernel 
//  getpnt_circle (x,y,c,r,t); 
//  getpnt_square (x,y,c,r,t); 
     getpnt_hexagon(x,y,c,r,t); 
     // render it 
     xx=xs2+x; 
     yy=ys2+y; 
     bmp->Canvas->LineTo(xx,yy); 
     bmp->Canvas->Ellipse(xx-rr,yy-rr,xx+rr,yy+rr); 
     // update position 
     r+=dr*dr/(r*c); 
     t+=dl/(r*c); t-=floor(t); 
     if (r>=xs2) break; 
     if (r>=ys2) break; 
     } 

    // render backbuffer 
    Main->Canvas->Draw(0,0,bmp); 
    _redraw=false; 
    } 
//--------------------------------------------------------------------------- 

können Sie die VCL/GDI Rendering Sachen ignorieren.
xs,ys ist voll und xs2,ys2 ist halbe Auflösung des Fensters richtig um den Plot zu skalieren ...
dl ist Abstand zwischen den Markern [pixels]
dr ist Abstand zwischen Spiralschrauben [pixels]

die Spirale mit r,t Schritt abgetastet wird in Abhängigkeit von der tatsächliche Umfang (das ist, was die pi2 oder c ist). Die getpnt_xxxxx Funktion gibt x,y Koordinate Ihrer Form von Parameter t=<0,1> und tatsächlichen Radius r zurück. Es gibt auch den tatsächlichen Wert von circumference/r Verhältnis pi2 für Spirale verwendet

Hier Vorschau der drei Kerne genannt ...

spirals

Verwandte Themen