Professional Documents
Culture Documents
Grafica Pe Calculator
Grafica Pe Calculator
www.cniv.ro
www.icvl.eu
©
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
/*
cout <<"*******************************************************"<<"\n";
cout <<" CURBE PLANE REMARCABILE "<<"\n";
cout <<" autor : M . Vlada "<<"\n";
cout <<"*******************************************************"<<"\n";
cout <<" 1 =concoida NICOMEDE 2 =melcul lui PASCAL "<<"\n";
cout <<" 3 =cisoida DIOCLES 4 =cisoida elipsei "<<"\n";
cout <<" 5 =trisectoarea MAC-LAURIN 6 =trisectoarea LONGCHAMPS"<<"\n";
cout <<" 7 =cicloida 8 =epicicloida "<<"\n";
cout <<" 9 =hipocicloida 10=astroida "<<"\n";
cout <<" 11=strofoida 12=bucla MARIA AGNESI "<<"\n";
cout <<" ( centrul ecranului = originea sistemului cartezian ) "<<"\n";
cout <<"*******************************************************"<<"\n";
*/
//{=========================================================}
//program CURBE ; curbe plane remarcabile - ecuatii parametrice
#include <graphics.h>
#include <math.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#define pi M_PI
char solid[8]={255,255,255,255,255,255,255,255};
int graphdriver , graphmode;
char ch;
int graphX[740], graphY[740]; //array[-319..319] of integer;
double a , b , arg , val1 , val2;
int i , t1 , t2 , flag;
//==========================================================
void INIT()
{
graphdriver = DETECT;
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
initgraph (&graphdriver ,&graphmode , "C:\\Borlandc\\bgi"); //init
mod grafic
setfillpattern ( solid , 15);
bar ( 0,0 ,700,500 );
setcolor( 0 ) ;
setviewport ( 320 , 175 , 500 , 200 , 0 );//fixare origine
rectangle ( -150 , -150 , 150 , 150 ); //deseneaza un chenar
setviewport ( 170 , 25 , 470 , 325 , 1 ); //fixare fereastra
}
void STOP()
//iesire din modul grafic
{
getch(); // inghetare imagine
closegraph(); // iesire mod grafic
}
void AXE()
//------------
// deseneaza axele (format mic) in origine
{
moveto ( 120 , 150 );
lineto ( 180 , 150 );
moveto ( 150 , 120 );
lineto ( 150 , 180 );
}
cout <<"*******************************************************"<<"\n";
cout <<" CURBE PLANE REMARCABILE "<<"\n";
cout <<" autor : M . Vlada "<<"\n";
cout <<"*******************************************************"<<"\n";
cout <<" 1 =concoida NICOMEDE 2 =melcul lui PASCAL "<<"\n";
cout <<" 3 =cisoida DIOCLES 4 =cisoida elipsei "<<"\n";
cout <<" 5 =trisectoarea MAC-LAURIN 6 =trisectoarea LONGCHAMPS"<<"\n";
cout <<" 7 =cicloida 8 =epicicloida "<<"\n";
cout <<" 9 =hipocicloida 10=astroida "<<"\n";
cout <<" 11=strofoida 12=bucla MARIA AGNESI "<<"\n";
cout <<" ( centrul ecranului = originea sistemului cartezian ) "<<"\n";
cout <<"*******************************************************"<<"\n";
cout <<" precizitati numarul de ordine pentru curba dorita : "<<"\n";
cin >> flag;
switch (flag){
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
case 1:
{ // ================= curba lui NICOMEDE ===============
cout <<" curba lui NICOMEDE ";
cout <<" dati parametri a , b = "; cin >> a; cin>>b;
t1 = round( (- pi / 2.0)*100) ; t2 =round( (pi / 2.0)*100);
//factorul 100 reprezinta scalarea imaginii
for(i = t1; i <= t2; i++)
{
arg = i / 100.00 ;
//vectorii graphX, graphY retin coordonatele pentru
desenare
graphX [i+319] = round( ( a + b * cos (arg) ) * 100 )+150
;
graphY [i+319] = round( ( a*sin(arg)/cos(arg) +
b*sin(arg))*100)+150;
}
INIT();
AXE();
GRAPH1 ( t1 , t2 );
for(i = t1; i <= t2; i++)
{
arg = i / 100.00 ;
graphX[i+319] = round( ( a - b * cos(arg) ) *100
)+150 ;
graphY[i+319] = round( ( a*sin(arg)/cos(arg) -
b*sin(arg))*100)+150;
}
GRAPH1 ( t1 , t2 ) ; break;
}
// =================== melcul lui PASCAL ===================
case 2 :
{ cout <<" melcul lui PASCAL "<<"\n";
cout <<" dati parametri a ,b = ";
cin >> a;
cin >> b;
t1 = round( -pi * 90 ) ; t2 = - t1 ;
for(i = t1; i <= t2; i++)
{
arg = i / 90.00 ;
graphX[i+319] = round( ( 2 *(a * cos(arg) +
b)*cos(arg) ) * 90 );
graphY[i+319] = round( ( 2 *(a * cos(arg) +
b)*sin(arg) ) * 90 );
graphX[i+319] = graphX[i+319] + 150 ; graphY[i+319] =
graphY[i+319] + 150;
}
INIT();
AXE();
GRAPH1 ( t1 , t2 ) ; break;
}
// =========== cisoida lui DIOCLES ( cisoida cercului =========
case 3 :
{
cout <<" cisoida lui DIOCLES ( cisoida cercului "<<'\n';
cout<<" dati parametrul a = "; cin >> a;
t1 = round ( (-pi /2.0 ) * 90 ) ; t2 = - t1 ;
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
for(i = t1; i <=t2; i++)
{
arg = i / 90.0 ;
graphX[i+319] = round( ( 2*a*sin(arg) *sin(arg) ) * 90 ) + 150 ;
graphY[i+319] = round( ( 2*a*sin(arg)*sin(arg)*sin(arg)
/cos(arg) )
* 90 ) + 150 ;
}
INIT();
AXE();
GRAPH1 ( t1 , t2 ) ; break;
}
// ========================= cisoida elipsei ====================
case 4 :
{
cout <<" cisoida elipsei ";
cout<<" dati parametri a , b = "; cin >> a>> b;
t1 = round( ( - pi / 2.0 ) * 90 ) ; t2 = - t1 ;
for( i = t1; i<= t2; i++)
{
arg = i / 90.0 + 0.01 ;
graphX[i+319] = round( ( 2*a*a*a / ( a*a + b*b*
pow(( cos(arg) / sin(arg) ),2)
) ) * 90 ) + 150 ;
graphY[i+319] = round( ( 2*a*a*a / ( a*a * cos(arg) / sin(arg) +
b*b * pow( ( cos(arg) / sin(arg)
),2) *
( cos(arg) / sin(arg) ) ) ) * 90
) + 150 ;
}
INIT();
AXE();
GRAPH1 ( t1 , t2 ) ; break;
}
// ================== trisectoarea lui MAC - LAURIN ==================
case 5 :
{
cout <<" trisectoarea lui MAC - LAURIN "<<"\n";
cout <<" dati parametrul a = "; cin>> a;
t1 = round ( ( - pi / 2.0 ) * 90 ) ; t2 = - t1 ;
for( i= t1; i<=t2; i++)
{
arg = i / 90.0 + 0.01 ;
graphX[i+319] = round ( ( 4 * a * cos(arg) * cos(arg) - a) *
90)+150;
graphY[i+319] = round ( ((4 * a * cos(arg) * cos(arg) - a) *
sin(arg) / cos(arg) ) * 90 )
+ 150 ;
}
INIT();
AXE();
GRAPH1 ( t1 , t2 ) ; break;
}
// ==================== trisectoarea lui LONGCHAMPS ===================
case 6 :
{
cout <<" trisectoarea lui LONGCHAMPS ";
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
cout <<" dati parametrul a = "; cin >> a;
t1 = round ( ( - pi / 2.0 ) * 50 ) ; t2 = - t1 ;
for( i = t1; i <= t2; i++)
{
arg = i / 50.0 + 0.01 ;
graphX[i+319] = round ( ( a / ( 4 * cos(arg)*cos(arg) -3) ) *50)
+150;
graphY[i+319] = round ( ( ( a* sin(arg) /cos(arg) ) / ( 4 *
cos(arg) * cos(arg) - 3 ) ) *
50 ) + 150 ;
}
INIT();
AXE();
GRAPH1 ( t1 , t2 ) ; break;
}
INIT() ;
AXE() ;
GRAPH1 ( t1 , t2 ) ; break;
}
Program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Grafica
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
}
}
}
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
namespace Grafica
{
public partial class Form1 : Form
{
private Bitmap buffer; // va contine figura ce se deseneaza la
un moment dat; dupa ce am terminat, se va salva figura pe canvas
private Bitmap canvas; // va contine imaginea finala
private Graphics canvasGraphics;
private Graphics bufferGraphics;
public Form1()
{
InitializeComponent();
}
bufferGraphics.DrawImage(bm, Ax + x, Ay + y);
bufferGraphics.DrawImage(bm, Ax + y, Ay + x);
bufferGraphics.DrawImage(bm, Ax - y, Ay - x);
bufferGraphics.DrawImage(bm, Ax - x, Ay - y);
bufferGraphics.DrawImage(bm, Ax + x, Ay - y);
bufferGraphics.DrawImage(bm, Ax - x, Ay + y);
bufferGraphics.DrawImage(bm, Ax + y, Ay - x);
bufferGraphics.DrawImage(bm, Ax - y, Ay + x);
}
}
Într-un sistem cartezian de axe XOY, considerăm un domeniu ce este determinat de o linie
poligonală oarecare şi închisă P = P1P2 ... Pn , unde punctele Pi (xi , yi ), i= 1…n sunt
determinate de coordonatele carteziene (xi , yi ), i= 1…n . Aria domeniului este data de
urmatoarea formula:
Programul va afisa fereastra prezentata mai jos (Height = 300, Width = 450)
si care ofera un meniu in partea inferioara, format din butoane pentru actiuni utile pentru
aplicatie:
• Erase all (New) - stergerea tuturor elementelor din zona de editare
• Load from file - incarcarea unui fisier deja creat
• Save to a file - salvarea coordonetelor punctelor intr-un fisier
• Edit – modificarea / editarea punctelor deja introduse
• Compute Area – activ (se va calcula aria domeniului poligonal) dupa
introducerea in zona de editare a punctelor poligonului
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
Calculul ariei
Program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace PolygonalArea
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false
);
Application.Run( new Form1() );
}
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PolygonalArea
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
graphicArea.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace PolygonalArea
{
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
internal struct Edge
{
public int v1, v2;
private double distance( int x1, int y1, int x2, int y2 )
{
return Math.Sqrt( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( (
y1 - y2 ) * ( y1 - y2 ) ) );
}
count = reader.ReadLine();
if( notAnInt( count ) )
return new List<Point>();
edges = new List<Edge>( System.Convert.ToInt32( count
) );
progressBarContainer.Text = "Loading Edges...";
progressBar.Maximum = edges.Capacity;
for( int j = 0; j < edges.Capacity; j++ )
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
{
progressBar.Value = j;
string endPoints = reader.ReadLine();
string[] index = endPoints.Split( ' ' );
int v1 = 0, v2 = 0;
if( notAnInt( index[ 0 ] ) || notAnInt( index[
1 ] ) )
{
//todo: warn: not an int
}
else
{
v1 = Convert.ToInt32( index[ 0 ] );
v2 = Convert.ToInt32( index[ 1 ] );
edges.Add( new Edge( v1, v2 ) );
}
}
progressBarContainer.Visible = false;
reader.Close();
checkIntersections();
chkEdit.Enabled = true;
return result;
}
polygonalArea.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PolygonalArea
{
//class polygonalArea : action
//{
//}
private bool intersect( Point p1, Point p2, Point p3, Point
p4, ref Point i )
{
if( p1.Y == p2.Y )
{
if( p3.Y == p4.Y ) //both pairs of Y's are
equal
if( p1.Y != p3.Y )
return false;
else
{
i.X = getMiddle( p1.X, p2.X, p3.X,
p4.X );
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
i.Y = p1.Y;
return ( i.X > 0 );
}
else
{
double m34 = System.Convert.ToDouble(
p3.X - p4.X ) / ( p3.Y - p4.Y );
i.Y = p1.Y;
i.X = ( int )Math.Round( p4.X + m34 * (
i.Y - p4.Y ) );
return isBetween( p1, p2, i ) &&
isBetween( p3, p4, i );
}
}
else
if( p3.Y == p4.Y )
{
double m12 = System.Convert.ToDouble(
p1.X - p2.X ) / ( p1.Y - p2.Y );
i.Y = p4.Y;
i.X = ( int )Math.Round( p1.X + m12 * (
i.Y - p1.Y ) );
return isBetween( p1, p2, i ) &&
isBetween( p3, p4, i );
}
else //both pairs of Y's are different
{
double m12 = System.Convert.ToDouble(
p1.X - p2.X ) / ( p1.Y - p2.Y );
double m34 = System.Convert.ToDouble(
p3.X - p4.X ) / ( p3.Y - p4.Y );
if( p1.X == p2.X )
{
i.X = p1.X;
if( p3.X == p4.X )
if( p1.X == p4.X )
{
i.Y = getMiddle( p1.Y,
p2.Y, p3.Y, p4.Y );
return ( i.Y > 0 );
}
else
return false;
else
{
i.Y = ( int )Math.Round( p3.Y
+ ( i.X - p3.X ) / m34 );
return isBetween( p1, p2, i )
&& isBetween( p3, p4, i );
}
}
else //m12 <> 0
{
if( p3.X == p4.X )
{
i.X = p4.X;
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
i.Y = ( int )Math.Round( p1.Y
+ ( i.X - p1.X ) / m12 );
return isBetween( p1, p2, i )
&& isBetween( p3, p4, i );
}
else //m34 <> 0 too, so both pairs
of X's are also different
{
if( ( p1.X - p2.X ) * ( p3.Y
- p4.Y ) == ( p1.Y - p2.Y ) * ( p3.X - p4.X ) )
{
//parallel!
double m14 =
System.Convert.ToDouble( p1.X - p4.X ) / ( p1.Y - p4.Y );
if( ( ( int
)Math.Round( 1000 * ( m12 - m14 ) ) ) == 0 )
{
i.Y = getMiddle(
p1.Y, p2.Y, p3.Y, p4.Y );
i.X = p1.X + (
int )Math.Round( m12 * ( i.Y - p1.Y ) );
return ( i.Y > 0
);
}
else
return false;
}
else
{
i.Y = ( int
)Math.Round( ( ( m34 * p3.Y - m12 * p1.Y ) + ( p1.X - p3.X ) ) / ( m34
- m12 ) );
i.X = p1.X + ( int
)Math.Round( m12 * ( i.Y - p1.Y ) );
if( Math.Abs( ( i.X -
p3.X ) - m34 * ( i.Y - p3.Y ) ) > 6 )
i.X = p3.X + (
int )Math.Round( m34 * ( i.Y - p3.Y ) );
return isBetween( p1,
p2, i ) && isBetween( p3, p4, i );
}
}
}
}
}
private int getMiddle( int p1, int p2, int p3, int p4 )
{
int result = 0;
if( isBetween( p1, p2, p3 ) && isBetween( p1, p2, p4
) )
result = ( p3 + p4 ) / 2;
if( isBetween( p3, p4, p1 ) && isBetween( p3, p4, p2
) )
result = ( p1 + p2 ) / 2;
if( isBetween( p1, p2, p3 ) && isBetween( p3, p4, p1
) )
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
result = ( p1 + p3 ) / 2;
if( isBetween( p1, p2, p3 ) && isBetween( p3, p4, p2
) )
result = ( p2 + p3 ) / 2;
if( isBetween( p1, p2, p4 ) && isBetween( p3, p4, p1
) )
result = ( p1 + p4 ) / 2;
if( isBetween( p1, p2, p4 ) && isBetween( p3, p4, p2
) )
result = ( p2 + p4 ) / 2;
return result;
}
private void fillTriangle( int i1, int i2, int i3, Brush
fillColor )
{
Graphics.FromImage( picBox.Image ).FillPolygon(
fillColor, new Point[] { v[ i1 ], v[ i2 ], v[ i3 ] } );
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
picBox.Invalidate();
}
21 8 8 6 11
177 100 182 22 64 26 149 124 179 23
203 17 243 31 44 103 62 74 56 55
233 17 292 60 108 150 150 22 240 65
262 23 326 103 160 73 222 22 61 97
291 17 172 118 182 148 110 66 330 142
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
321 17 35 103 296 129 222 83 166 100
338 41 86 52 174 83 6 320 51
347 74 128 30 295 28 0 1 142 46
332 100 8 8 1 2 342 30
349 125 0 1 0 1 2 3 237 11
177 136 1 2 1 2 3 4 208 29
21 132 2 3 2 3 4 5 11
44 112 3 4 3 4 5 0 0 1
19 79 4 5 4 5 1 2
20 49 5 6 5 6 2 3
55 51 6 7 6 7 3 4
47 16 7 0 7 0 4 5
89 43 5 6
97 14 6 7
126 21 7 8
152 45 8 9
21 9 10
0 1 10 0
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19