Add to Favorites    Make Home Page 14673 Online  
 Language Categories  
 Our Services  

Home » C++ Home » Computer Graphics Home »

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title
Author Bikramjit Sharma
Author Email sharma_bikramjit [at] yahoo.com
Description the program is used to generate the node coordinates and
element connectivities used for FEM using rectangular elements. the
domain
has a hole inside it, so discretiztion maually becomes complex but with
this program it takes much lesser time to generate the same and with
graphics visulization
Category C++ » Computer Graphics
Hits 366087
Code Select and Copy the Code
#include "myheader.h" //automatic discretization using rectangular elements. //single hole in geometry //the nuber of divisions,hole position and size are given by user. //press enter to accept an element any other to disapprove float x[4]={50,250,250,50},y[4]={50,50,100,100},n[4],cirx[32],ciry[32];//domain coordinates float xc,yc; //shape function void shape_fn(float zi,float ita,float n[]) { n[0]=(1-zi)*(1-ita)/4; n[1]=(1+zi)*(1-ita)/4; n[2]=(1+zi)*(1+ita)/4; n[3]=(1-zi)*(1+ita)/4; } void modifyval(float &xl,float &yl) { char ch; gotoxy(20,25); cout<<xl<<" "<<yl; if(xl==xc&&yl==yc) { cout<<"a central node found choose any of the values below"; cout<<cirx[0]<<ciry[0]<<"1"<<endl; cout<<cirx[15]<<ciry[15]<<"2"<<endl; cout<<cirx[24]<<ciry[24]<<"3"<<endl; cout<<cirx[31]<<ciry[31]<<"4"<<endl; cin>>ch; if(ch==1) xl=cirx[0];yl=ciry[0]; if(ch==2) xl=cirx[15];yl=ciry[15]; if(ch==3) xl= cirx[24];yl=ciry[24]; if(ch==4) xl=cirx[31];yl=ciry[31]; } long double d,dmin; float xlt,ylt; int i; xlt=xl; ylt=yl; dmin=sqrt((xl-cirx[0])*(xl-cirx[0])+(yl-ciry[0])*(yl-ciry[0])); for( i=0;i<32;i++) { d=sqrt((xlt-cirx[i])*(xlt-cirx[i])+(ylt-ciry[i])*(ylt-ciry[i])); if(d==dmin) { xl=cirx[0]; yl=ciry[0]; } if(d<dmin) { dmin=d; xl=cirx[i]; yl=ciry[i]; } // gotoxy(20,25); // cout<<dmin<<" "<<d<<" "<<xl<<" "<<yl; } } //main starts void main() { //initialization of variables and first time drawing of domain. int gd=DETECT,gm,i,j,e=0,k=0,xdiv,ydiv,no_of_element,no_of_node,**connect; float zi,ita,*xl,*yl,r,u,t1,t2; FILE *fout; fout=fopen("ad3-out.txt","w"); initgraph(&gd,&gm,"c:\tc\bgi"); setcolor(BLUE); moveto(x[3],y[3]); for(i=0;i<4;i++) lineto(x[i],y[i]); cout<<"enter no.of divisions in x and y direction::"; cin>>xdiv>>ydiv; no_of_element=xdiv*ydiv; no_of_node=(xdiv+1)*(ydiv+1); // cout<<"domain size::"<<no_of_element<<" elements "<<no_of_node<<" nodes"; connect=new int*[no_of_element]; for(i=0;i<no_of_element;i++) connect[i]=new int[no_of_node]; for(i=0;i<no_of_element;i++) { for(j=0;j<no_of_node;j++) { connect[i][j]=0; } } xl=new float[no_of_node]; yl=new float[no_of_node]; // xlf=new float[no_of_node]; //THESE VALUES WILL BE USED FOR COMPARISONS // ylf=new float[no_of_node]; cout<<" enter postion of hole"; cin>>xc>>yc; cout<<"hole size/radius"; cin>>r; for(u=0,i=0;u<=(360*M_PI/180);u=u+0.2) { cirx[i]=xc+ r*cos(u); ciry[i]=yc+r*sin(u); // gotoxy(20,20); // cout<<cirx[i]<<" "<<ciry[i]; putpixel( cirx[i],ciry[i],RED); i++; //getch(); } for(i=0;i<=xdiv;i++) { zi=(-1+(2.0*i/xdiv)); for(j=0;j<=ydiv;j++) { ita=(-1+(2.0*j/ydiv)); shape_fn(zi,ita,n); xl[e]=x[0]*n[0]+x[1]*n[1]+x[2]*n[2]+x[3]*n[3]; yl[e]=y[0]*n[0]+y[1]*n[1]+y[2]*n[2]+y[3]*n[3]; if((xl[e]>=(xc-r)&&xl[e]<=(xc+r))&&(yl[e]>=(yc-r)&&yl[e]<=(yc+r))) modifyval(xl[e],yl[e]); e++; } } e=0; for(i=0;i<no_of_node;i++) fprintf(fout,"%f %f ",xl[i],yl[i]); for(i=0;i<xdiv;i++) { for(j=0;j< ydiv;j++) { connect[e][0]=i*(ydiv+1)+j; connect[e][1]=connect[e][0]+ydiv+1; connect[e][2]=connect[e][1]+1; connect[e][3]=connect[e][0]+1; e++; } } //final drawing of mesh for(e=0;e<no_of_element;e++) { setcolor(YELLOW); moveto(xl[connect[e][3]],yl[connect[e][3]]); for(i=0;i<4;i++) lineto(xl[connect[e][i]],yl[connect[e][i]]); gotoxy(30,20); cout<<"whether accept?"; if(getch()==13) { setcolor(GREEN); moveto(xl[connect[e][3]],yl[connect[e][3]]); for(i=0;i<4;i++) lineto(xl[connect[e][i]],yl[connect[e][i]]); fprintf(fout,"%d %d %d %d ",connect[e][0],connect[e][1],connect[e][2], connect[e][3]); k++; } else{ setcolor(RED); moveto(xl[connect[e][3]],yl[connect[e][3]]); for(i=0;i<4;i++) lineto(xl[connect[e][i]],yl[connect[e][i]]); } fflush(stdin); } cout<<" domain size::"<<k<<" elements "<<no_of_node<<" nodes "; fclose(fout); getch(); closegraph(); }

Related Source Codes

Script Name Author
Moving ball screen saver karlmarx
The Classic Game of Snake & Ladder Lakshmi Narayana .A
Railway seat reservation question which comes in sapient VyomWorld
To calculate percentile Ravi Mathur
Send to folder ANIMESH SAHU
Analog clock and calendar Nazia & Rida
HIGH/LOW GAME MOLLY ARORA
Data structure (stack Implimentation) Swapnil B Adsure
Memory Game AnirudhSanyal
Easy Calc Anirudh Sanyal
GK Quiz Anirudh Sanyal
Hangman Game Manish Jain
Snakeman Manish Jain
Full month Calendar Nigi
Cursor shapes nigi

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=1146


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review