com 366 reading data. com 366 reading data from disc files organise the data in a logical fashion...
TRANSCRIPT
![Page 1: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/1.jpg)
COM 366
Reading Data
![Page 2: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/2.jpg)
COM 366
Reading data from disc files
Organise the data in a logical fashion with comments as necessary.
#Data for a cube# First the link data121,22,33,44,11,52,63,74,85,66,77,88,5#Now the node data81,-1,1-1,-1,1-1,1,11,1,11,-1,-1-1,-1,-1-1,1,-11,1,-1
#Data for a cube# First the link data121,22,33,44,11,52,63,74,85,66,77,88,5#Now the node data81,-1,1-1,-1,1-1,1,11,1,11,-1,-1-1,-1,-1-1,1,-11,1,-1
![Page 3: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/3.jpg)
COM 366
Open filename For Input As #1 Input #1, temp_line While Left$(temp_line, 1)= "#"
Input #1, temp_lineWend
num_lines = Clnt(temp_line) ReDim L(2, num_lines)
For i = 1 To num lines Input #1, L(1, i), L(2, i)
Next i input #1, temp_line While Left$(temp_line, 1)= "#"
Input #1, temp_line Wend
num_points = Clnt(temp_line) ReDim X(num_points), Y(num_points), Z(num_points) For i = 1 To num_points
Input #1, V(i).X, V(i).Y, V(i).Z Next i
Close #1
A simple procedure to read the text file
![Page 4: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/4.jpg)
COM 366
Topic 6
Data structures revisited
![Page 5: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/5.jpg)
COM 366
(a) (b) (c) (d)
Figure 6.1
Representing Objects with polygons
![Page 6: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/6.jpg)
COM 366
OBJECTOBJECT
Node # Co-ordinates
V1
V2
V3
Vm
x1,y1,z1
x2,y2,z2
x3,y3,z3
xm,ym,zm
Figure 6.2 : Object Data Structure
FACE LIST
V1,V2,V3,....
V2,V3,V12,....
V6,V3,V9,....
V11,V21,V3,....
Face #
F1
F2
F3
F4
Properties
Colour, textureAppearance etc.
“
“
“
Data structure for an object
![Page 7: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/7.jpg)
COM 366
X
Y
Z
CO
X
X
Y
Y
Z
Z
H1O
H2O
GO
X
Y
Z
Figure 6.3
Local & global co-ordinates
![Page 8: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/8.jpg)
COM 366
Scene
Object 1 Object 2 Object 3
Lighting Cameraview
Figure 6.4
Data structure for a scene
![Page 9: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/9.jpg)
COM 366
Figure 6.5
Sweep generation of an object
![Page 10: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/10.jpg)
COM 366
N = 6
N = 30
Axis of symmetry
![Page 11: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/11.jpg)
COM 366
function RevObject(n)
%To generate a 3D object from profile in 'goblet.txt'
%NOTE this version only works with 5 nodes in the profile
%First read in the data, set the number of nodes and faces
U = dlmread('goblet.txt');
[a,b] = size(U);
numnodes = a*n;
numpatch = (a-1)*n;
Node = zeros(numnodes,3);
PSet = zeros(numpatch,4);
%Now calculate all the node values
for k = 0:n-1
for L = 1:a
theta = 2*k*pi/n;
Node(L+a*k,1) = U(L,1)*cos(theta);
Node(L+a*k,2) = U(L,1)*sin(theta);
Node(L+a*k,3) = U(L,2);
end;
end;
![Page 12: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/12.jpg)
COM 366
for k = 1:n
term = 5*(k-1);
for L = 1:4
Pset(4*(k-1)+L,:) = [(term+L) (term+L+1) (term+L+6) (term+L+5)];
end
end;
%Finally ensure that the last but one profile connects to the first
for k = numpatch-3:numpatch
Pset(k,3)=Pset(k,3)-numnodes;
Pset(k,4) = Pset(k,4) - numnodes;
end
%Uncomment the following line if you want to see the patch array
%Pset
patch('Vertices',Node,'Faces',Pset,'facevertexCdata',[0.2 0.2 1],'facecolor','flat')
axis square
rotate3d on
![Page 13: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/13.jpg)
COM 366
A B X
Figure 6.3
Constructive solid geometry - 1
X A B
![Page 14: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/14.jpg)
COM 366
Constructive solid geometry - 2
X A B
A B X
Figure 6.4
![Page 15: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/15.jpg)
COM 366
X A B
Constructive solid geometry - 3
A B A - B
Figure 6.5
B - A
![Page 16: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/16.jpg)
COM 366
[X,Y,Z] = cylinder
[X,Y,Z] = cylinder(r)
[X,Y,Z] = cylinder(r,n)
Three forms of the cylinder function
![Page 17: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/17.jpg)
COM 366
function [X,Y,Z] = Cone(R,h,L)%To create X,Y,Z data to draw a truncated cone.%R = base radius of the cone.%h = height to which the cone is drawn%L = apex of the cone%Note setting h = L will draw the full coneif nargin < 3, L = 1; endif nargin < 2, h = L; endif nargin == 0, R = 1; endstepsize = h/10;t = 0:stepsize:h;[X,Y,Z] = cylinder((R*(1-t/L)));
L
tRr 1.
When t = 0 then r = R
When t = L then r = 0
Generating a cone
![Page 18: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/18.jpg)
COM 366
h = L h < L
Examples of cone
![Page 19: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/19.jpg)
COM 366
Superquadratics
Example the super ellipse
)(sin.
)(cos.
m
m
by
ax
m = 1 gives a normal ellipse
m >1 gives a cusped figure
m < 1 gives a ‘fatter figure
m = 0 gives a rectangle
![Page 20: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/20.jpg)
COM 366
Superquadratics in 3D (superquad)
![Page 21: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/21.jpg)
COM 366
Using Fractals
![Page 22: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/22.jpg)
COM 366
The Koch Curve
N=0N=1
N=2 N=5
![Page 23: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/23.jpg)
COM 366
Length of the Koch Curve
N = 1 2 3 …………… m
33.13
1.4 78.1
9
1.16 37.2
27
1.64
length then As m
mm
3
1.4
![Page 24: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/24.jpg)
COM 366
Dimension of the Koch Curve
Definition of space dimensionIf N is the number of self similar copies required when an object is scaled by r then the
Dimension of the object ‘D’ is given by :
1 = NrD
If a line is scaled by 1/3 then 3 copies are required thus the
dimension of a line is 1 = 3(1/3)D. Therefore D = 1
If a square is scaled by 1/3 then 9 copies are required thus the
dimension of a square is 1 = 9(1/3)D. Therefore D = 2
For the Koch curve if we scale by 1/3 we require 4 sections and the dimension is
2857.1)3log(
)4log(D
![Page 25: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/25.jpg)
COM 366
Using ‘graftals’The correct name is parallel graph grammars
Definitions (you can improvise your own)
1. A AA
2. B A[B]AA[B]
3. [ ] means ‘branch left
If we start with A we generate a dull sequence A AA AAAA etc. But lets start with B and
Record the first 3 generations :
(0) B (1) A[B]AA[B] (2) AA[A[B]AA[B]]AAAA[A[B]AA[B]]
B
B
B
A
A
A
B B
B B
A
A
A
A
A
A
AAA
AAA
![Page 26: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/26.jpg)
COM 366
Change the angle between turns and introduce () to mean branch right and we start to
Get more interesting shapes
![Page 27: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/27.jpg)
COM 366
Use curved segments and colour Finally add some random
variation in angles and lengths
Making ‘graftals’ realistic
![Page 28: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/28.jpg)
COM 366
Modelling mountains
RxxPyyy
xxx
iiiinew
iinew
.2
12
1
11
1
P is a perturbation based on the length ‘s’ of the line e.g. 2-s and R is a random number between 0 and 1
0 1 2
In three dimensions the concept is exactly the same but using a triangle or pyramid as a starting point
![Page 29: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/29.jpg)
COM 366
Add some colour and and shading !
![Page 30: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/30.jpg)
COM 366
Topic 7
Hidden Surface Removal
![Page 31: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/31.jpg)
![Page 32: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/32.jpg)
COM 366
Convex Solids
A solid is convex if a straight line joining any two points on the surface passes entirely through the body of the solid or through its surface.
Examples of common convex solids include :
Sphere, cube, cone, cylinder, pyramid
All remaining solids are non convex
![Page 33: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/33.jpg)
![Page 34: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/34.jpg)
N
L Towards the viewer
![Page 35: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/35.jpg)
COM 366
Criteria of Visibility
The polygon surface is visible if
0 90o or 270o 360o
Or in terms of the angle cosine Cos() 0
NL
NL
.cos
![Page 36: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/36.jpg)
COM 366
L = (Lx,Ly,Lz)
Numerical evaluation of the visibility condition
Viewing direction
N = (Nx,Ny,Nz) Surface normal
If these two vectors are of unit length then
|L| = |N| = 1
L N L L L N N N L N L N L Nx y z x y z x x y y z z ( , , ) ( , , )
When viewing along the z axis L reduces to (0,0,-1)
cos( ) N z 0 0 or N z
![Page 37: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/37.jpg)
COM 366
Programming the visibility criterion
My recommendation is that you add all the normals to your data structure (NX,NY,NZ) and then rotate them with the nodes before applying the visibility criterion
![Page 38: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/38.jpg)
COM 366
Hidden Surface Removal for Non Convex Objects
The painters ( or z buffer) algorithm
If we can, in an unambiguous manner, sort the polygons into order of increasing z values then we can correctly render the object by drawing the polygons with the largest z values first. Remember that for a left handed co-ordinate system the polygons with the largest z value will be the furthest from the view point.
![Page 39: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/39.jpg)
![Page 40: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/40.jpg)
![Page 41: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/41.jpg)
![Page 42: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/42.jpg)
Test 1 : Do the X extents of P and Q not overlap ?
Test2 : Do the Y extents of P and Q not overlap ?
Test3 : Is P completely on the side of the plane of Q away from the viewer ?
Test4 : Is Q completely on the side of the plane of P nearer to the viewer ?
Test5 : Do the projections of the two polygons on the viewing plane not overlap ?
![Page 43: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/43.jpg)
COM 366
The depth buffer method
This method like the z buffer algorithm begins with a list of polygons but makes no attempt to sort the polygons by z depth instead two pixel based buffers are created. For each pixel position we store the current pixel colour in one buffer. The second buffer contains a single z value at each pixel position representing the depth of the currently displayed pixel.
![Page 44: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/44.jpg)
![Page 45: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/45.jpg)
COM 366
For all pixels Set pixel_colour = background Set pixel_depth = maximum_valueEnd for all pixels
For each polygon For each projected_polygon_pixel If z_co_ord < pixel_depth then Set pixel_colour = ploygon_colour Set pixel_depth = z_co_ord Endif End for each projected_polygon_pixel
End for each polygon
![Page 46: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/46.jpg)
COM 366
![Page 47: COM 366 Reading Data. COM 366 Reading data from disc files Organise the data in a logical fashion with comments as necessary. #Data for a cube # First](https://reader035.vdocuments.mx/reader035/viewer/2022062805/5697bffd1a28abf838cc1dfb/html5/thumbnails/47.jpg)
COM 366
Type Vector x as
single y as
single z as
singleEnd type
Type Vector x as
single y as
single z as
singleEnd type
Type PolygonN as vectorCR as integerCG as integerCB as integerV() as integer
End Type
Type PolygonN as vectorCR as integerCG as integerCB as integerV() as integer
End Type
GLOBAL Object() as integer ‘The array of polygon numbers
GLOBAL Poly() as Polygon ‘ The array of polygons
GLOBAL Node() as Vector ‘ The array of vertex co-ordinates
GLOBAL num_polygons, num_nodes as integer.
GLOBAL Object() as integer ‘The array of polygon numbers
GLOBAL Poly() as Polygon ‘ The array of polygons
GLOBAL Node() as Vector ‘ The array of vertex co-ordinates
GLOBAL num_polygons, num_nodes as integer.
Programming in VB