Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


An eassy procedure to draw a Vector Field Format this article printer-friendly!Bookmark function is only available for registered users!
Vector Field
Product:
Delphi 5.x (or higher)
Category:
Algorithm
Skill Level:
Scoring:
Last Update:
04/25/2003
Search Keys:
delphi delphi3000 article borland vcl code-snippet Vectors, Draw, Chart
Times Scored:
2
Visits:
2600
Uploader: camilo Ernesto Pinilla Urzola
Company: Personal
Reference: N/A
 
Question/Problem/Abstract:
This coded is useful is you have to draw a velocity field in a two dimensional mesh
Answer:



This procedure draw vectors on a Chart component.


procedure TDatosInput.Vector(VArrayX,VArrayY: TArray2D; VArrayU,VArrayV: TArray3D; nx,ny,nt: DWord; Malla: TPointSeries; Chrt: TChart; ColorVector: TColor; Fact: DWord);
var
i,j,PosX: DWord;
xi,yi,xf,yf: Longint;
Xn,Yn: Extended;
Dx,Dy: Extended;
Ang: Extended;
begin

  {Config Canvas}
  Chrt.Canvas.Pen.Color:=ColorVector;
  Chrt.Canvas.Brush.Color:=ColorVector;

  {Paint Color at each cell}
  for j:=0 to ny-1 do
  for i:=0 to nx-1 do
  begin

    {Calc Angle}
    PosX:=i;
    if (i = nx-1) then PosX:=nx-2;
    Dx:=VArrayX[PosX+1,j]-VArrayX[PosX,j];
    Dy:=VArrayY[PosX+1,j]-VArrayY[PosX,j];

    {Check Dx}
    Ang:=0;
    if (Dx = 0) or (Dy = 0) then
      begin
        if (Dy > 0) and (Dx = 0) then Ang:=0.5*Pi;
        if (Dy < 0) and (Dx = 0) then Ang:=1.5*Pi;
        if (Dy = 0) and (Dx > 0) then Ang:=0;
        if (Dy = 0) and (Dx < 0) then Ang:=Pi;
      end
    else
      begin
        Ang:=ArcTan(Dy/Dx);
        {Check Position}
        if ((Dy > 0) or (Dy < 0)) and (Dx < 0) then
          Ang:=Ang+Pi;
      end;

    {New Coordinates - Rotating the Vector}
    xn:=VArrayU[i,j,nt]*Fact*Cos(Ang)-VArrayV[i,j,nt]*Fact*Sin(Ang);
    yn:=VArrayU[i,j,nt]*Fact*Sin(Ang)+VArrayV[i,j,nt]*Fact*Cos(Ang);

    {Drawing the Arrow}
    xi:=Malla.CalcXPosValue(VArrayX[i,j]);
    yi:=Malla.CalcYPosValue(VArrayY[i,j]);
    xf:=Malla.CalcXPosValue(xn+VArrayX[i,j]);
    yf:=Malla.CalcYPosValue(yn+VArrayY[i,j]);
    Chrt.Canvas.Arrow(False,Point(xi,yi),Point(xf,yf),5,10,0);
  end;

end;





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
L. Rosenstein
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)