2017-12-25 10 views
-4

sin(θ)*cos(θ)을 그려야하지만 작동하지 않습니다. sin 또는 cos, 을 그릴 수 있지만 sin(θ)*cos(θ)을 함께 그려야합니다. 여기 펜을 사용하여 C#에서 y = sin (θ) * cos (θ) 그리기

내 코드

private void button1_Click(object sender, EventArgs e) 
{ 
    Graphics drw = this.CreateGraphics(); 
    Pen pen = new Pen(Brushes.Black, 7.0f); 
    float x1 = 0; 
    float y1 = 0; 
    float xoy = 200; 
    float ef = 20; 

    for (double i=0;i<40;i+=1) 
    { 
     double radi = (float)(i * 180/Math.PI); 
     float temp = (float)Math.Cos(radi)*(float)Math.Sin(radi); 
     drw.DrawLine(pen, x1 * ef, y1 * ef + xoy, ef * (float)i, temp * ef + xoy); 
     x1 = (float)i; 
     y1 = temp; 
    } 
} 

내가이 결과 원하는 : enter image description here

+0

하십시오, 포스트도 당신의 결과. 감사합니다 – alepuzio

+0

이중 각 사인 공식을 사용하십시오 : sin (θ) cos (θ) = 1/2 sin (2θ)'.입력 매개 변수를 double *로하고, 결과 값을 plot * half *로 사인 곡선을 그립니다. 그래프 작성 계산기는 직교 좌표계에서 수직 좌표가 아닌 방사형 * 좌표로 'y'를 잘못 해석 한 것 같습니다. 'y = sin (x) * cos (x)'를 그려 보면 * 의도 한 * 결과를 얻을 수 있습니다. – meowgoesthedog

답변

0

이 코드의 출력입니다 :

enter image description here

을 그리고 이것은 Wolfram alpha's result입니다 :

enter image description here

Desmos's result 참조 :

enter image description here

따라서 당신이 y=sin (theta)*cos (theta)에 적합한 출력을 가지고있다. 0<=theta<=2*PI와 같은 또한 r은

+0

그는 이것을 원합니다 : [https://www.wolframalpha.com/input/?i=polar+plot+r%3Dsin(theta)*cos(theta)](https://www.wolframalpha.com/input/ ? i = polar + plot + r % 3Dsin (theta) * cos (theta)), 즉 파라 메트릭 플롯. 참고 : 매개 변수는 'x'가 아니라 'theta'입니다. –

1

범위 -1<=r<=1에 있어야

공지 사실, 당신이 찾고있는 실제 기능은 조금 다르다 ... 예 here를 참조하십시오. 극지 꽃에 관한 this article을 보면 올바른 방향으로 향하게 될 것이라고 확신하며 전체 작업 소스 코드도 포함되어 있습니다. 당신이 당신의 형태로 패널을 사용 랬

그냥 예는되는 극성 꽃립니다 :

panel.OnPaint += Panel_Paint; 

private void Panel_Paint(Object sender, PaintEventArgs e) 
{ 
    Double scale = ((Panel)sender).Width/2.0d; 
    Double repetitions = Math.Round(scale, 0); 
    Double basis = (2.0d * Math.PI)/scale; 
    Double petals = 2.0d; 

    using (Graphics g = e.Graphics) 
    { 
     using (Pen pen = new Pen(Brushes.Red, 2.0f)) 
     { 
      for (Double i = 0.0f; i < (repetitions - 1); ++i) 
      { 
       Double t0 = i*basis; 
       Double t1 = (i + 1)*basis; 

       Double x0 = Math.Sin(petals * t0) * Math.Cos(t0); 
       Double x1 = Math.Sin(petals * t1) * Math.Cos(t1); 

       Double y0 = Math.Sin(petals * t0) * Math.Sin(t0); 
       Double y1 = Math.Sin(petals * t1) * Math.Sin(t1); 

       g.DrawLine 
        (
         pen, 
         (Single) ((scale*x0) + scale), 
         (Single) ((scale*y0) + scale), 
         (Single) ((scale*x1) + scale), 
         (Single) ((scale*y1) + scale) 
        ); 
      } 
     } 
    } 
} 

기본 배합 상태를 그 petals 변수 값 인 경우 :

  • 심지어이면, 그것은 극지 꽃잎의 절반을 나타냅니다.
  • 홀수을 나타냅니다. 당신이 Double petals = 2.0d;를 정의하면 극 꽃

의 꽃잎의 NT 그래서, 당신은 ... 4 꽃잎을 얻을 것이다 당신이 Double petals = 5.0d;를 정의하면, 당신은 5 꽃잎을 얻을 것이다.

Output

1

당신은 쉽게 해당 Parametric Equations보고 찾을 수 있습니다.

enter image description here

private void Form1_Paint(object sender, PaintEventArgs e) 
    { 
     var g = e.Graphics; 

     double pi = Math.PI; 
     int n = 100; 
     var t = Enumerable.Range(0, n).Select(p => p * 2 * pi/n).ToArray(); 
     var x = t.Select(p => Math.Sin(2 * p) * Math.Cos(p)).ToArray(); 
     var y = t.Select(p => Math.Sin(2 * p) * Math.Sin(p)).ToArray(); 

     Pen pen = new Pen(Brushes.Black, 3); 

     int scale = 100; 
     int shift = 100; 
     for (int i = 0; i < n - 1; i++) 
     { 
      g.DrawLine(pen, scale*(float)x[i] + shift, 
       scale*(float)y[i] + shift, 
       scale*(float)x[i + 1] + shift, 
       scale*(float)y[i + 1] + shift); 
     } 
    } 
관련 문제