DIRECTORY PredefSweeps, RealFns, SV2d, SVPolygon2d, SVSweepGeometry; PredefSweepsImpl: CEDAR PROGRAM IMPORTS RealFns, SVPolygon2d, SVSweepGeometry EXPORTS PredefSweeps = BEGIN RevoluteMesh: TYPE = REF RevoluteMeshRecord; RevoluteMeshRecord: TYPE = SVSweepGeometry.RevoluteMeshRecord; LinearMesh: TYPE = REF LinearMeshRecord; LinearMeshRecord: TYPE = SVSweepGeometry.LinearMeshRecord; ToroidalMesh: TYPE = REF ToroidalMeshRecord; ToroidalMeshRecord: TYPE = SVSweepGeometry.ToroidalMeshRecord; Polygon: TYPE = SV2d.Polygon; Path: TYPE = SV2d.Path; linesOfLatitude: NAT _ 5; linesOfLongitude: NAT _ 8; SetLinesOfLatitude: PUBLIC PROC [lat: NAT] = { linesOfLatitude _ lat; }; SetLinesOfLongitude: PUBLIC PROC [long: NAT] = { linesOfLongitude _ long; }; GetLinesOfLatitude: PUBLIC PROC [] RETURNS [lat: NAT] = { lat _ linesOfLatitude; }; GetLinesOfLongitude: PUBLIC PROC [] RETURNS [long: NAT] = { long _ linesOfLongitude; }; CreateSphere: PUBLIC PROC [r: REAL] RETURNS [RevoluteMesh] = { x, y: REAL; path: Path _ SVPolygon2d.CreatePath[linesOfLatitude]; theta, deltaTheta: REAL; SVPolygon2d.PutPathPoint[path, 0, [0,r]]; theta _ 90.0; deltaTheta _ 180.0/(linesOfLatitude - 1); -- Nat to float? FOR i: NAT IN [2..linesOfLatitude-1] DO theta _ theta - deltaTheta; x _ r*RealFns.CosDeg[theta]; y _ r*RealFns.SinDeg[theta]; SVPolygon2d.PutPathPoint[path, i-1, [x,y]]; ENDLOOP; SVPolygon2d.PutPathPoint[path, linesOfLatitude-1, [0,-r]]; RETURN[SVSweepGeometry.RevoluteSweep[path, linesOfLongitude]]; }; CreateCube: PUBLIC PROC [side: REAL] RETURNS [LinearMesh] = { pos, neg: REAL; lin: LinearMesh; poly: Polygon _ SVPolygon2d.CreatePoly[4]; pos _ side*(0.5); neg _ side*(-0.5); poly _ SVPolygon2d.PutPolyPoint[poly, 0, [neg,pos]]; poly _ SVPolygon2d.PutPolyPoint[poly, 1, [pos,pos]]; poly _ SVPolygon2d.PutPolyPoint[poly, 2, [pos,neg]]; poly _ SVPolygon2d.PutPolyPoint[poly, 3, [neg,neg]]; lin _ SVSweepGeometry.LinearSweep[poly, pos, neg]; RETURN[lin]; }; CreateFullCylinder: PUBLIC PROC [r, h: REAL] RETURNS [RevoluteMesh] = { path: Path _ SVPolygon2d.CreatePath[linesOfLatitude]; height, deltaH: REAL; height _ h/2.0; deltaH _ h/(linesOfLatitude - 1); SVPolygon2d.PutPathPoint[path, 0, [r,height]]; SVPolygon2d.PutPathPoint[path, linesOfLatitude-1, [r,-height]]; FOR i: NAT IN [2..linesOfLatitude-1] DO height _ height - deltaH; SVPolygon2d.PutPathPoint[path, i-1, [r,height]]; ENDLOOP; RETURN[SVSweepGeometry.RevoluteSweep[path, linesOfLongitude]]; }; CreateCylinder: PUBLIC PROC [r, h: REAL] RETURNS [RevoluteMesh] = { path: Path _ SVPolygon2d.CreatePath[2]; height: REAL _ h/2.0; SVPolygon2d.PutPathPoint[path, 0, [r,height]]; SVPolygon2d.PutPathPoint[path, 1, [r,-height]]; RETURN[SVSweepGeometry.RevoluteSweep[path, linesOfLongitude]]; }; CreateCone: PUBLIC PROC [r, h: REAL] RETURNS [RevoluteMesh] = { path: Path _ SVPolygon2d.CreatePath[linesOfLatitude]; height, deltaH, x, deltaX: REAL; height _ h; deltaH _ h/(linesOfLatitude - 1); x _ 0; deltaX _ r/(linesOfLatitude - 1); SVPolygon2d.PutPathPoint[path, 0, [0,h]];-- top is on the y axis; SVPolygon2d.PutPathPoint[path, linesOfLatitude-1, [r,0]];-- base is on the xz plane FOR i: NAT IN [2..linesOfLatitude-1] DO height _ height - deltaH; x _ x + deltaX; SVPolygon2d.PutPathPoint[path, i-1, [x,height]]; ENDLOOP; RETURN[SVSweepGeometry.RevoluteSweep[path, linesOfLongitude]]; }; CreateTorus: PUBLIC PROC [rBig, rCross: REAL] RETURNS [ToroidalMesh] = { poly: Polygon _ SVPolygon2d.CreatePoly[linesOfLatitude]; alpha, deltaAlpha, sin, cos, x, y: REAL; -- the cross section circle alpha _ 0; deltaAlpha _ -360/linesOfLatitude; -- negative because ToroidalSweep assumes clockwise poly _ SVPolygon2d.PutPolyPoint[poly, 0, [rBig+rCross,0]]; FOR i: NAT IN[2..linesOfLatitude] DO alpha _ alpha + deltaAlpha; sin _ RealFns.SinDeg[alpha]; cos _ RealFns.CosDeg[alpha]; x _ rBig + rCross*cos; y _ rCross*sin; poly _ SVPolygon2d.PutPolyPoint[poly, i-1, [x,y]]; ENDLOOP; RETURN[SVSweepGeometry.ToroidalSweep[poly, linesOfLongitude]]; }; GetUnitSphere: PUBLIC PROC RETURNS [RevoluteMesh] = { RETURN[CreateSphere[1.0]] }; GetUnitCube: PUBLIC PROC RETURNS [LinearMesh] = { RETURN[CreateCube[2.0]] }; GetUnitCylinder: PUBLIC PROC RETURNS [RevoluteMesh] = { RETURN[CreateFullCylinder[1.0, 2.0]] }; GetUnitCone: PUBLIC PROC RETURNS [RevoluteMesh] = { RETURN[CreateCone[1.0, 1.0]] }; END. VFile: PredefSweepsImpl.mesa Last edited by Eric Bier on July 22, 1987 4:45:03 pm PDT Copyright c 1984 by Xerox Corporation. All rights reserved. Contents: A cube, a cylinder, a cone, a sphere and a torus are created at load time and made available Generate a semi-circle in the x-y plane with 10 points where the end two points are on the y axis Make sure the endpoints are as accurate as possible Generate a cone pointing up with the center of its circular base at the origin of the local cs Just define the translated circle which is the torus's cross section (see full cylinder for help) Κ|– "Mesa" style˜Iheadšœ™Iprocšœ8™8Jšœ Οmœ1™Lšœ žœ˜Lšœžœ ˜Lšœžœ˜Lšœžœ˜L˜—šΟnœžœžœžœ˜.Lšœ˜L˜L˜—šŸœžœžœžœ˜0Lšœ˜L˜L˜—š Ÿœžœžœžœžœ˜9Lšœ˜L˜—š Ÿœžœžœžœžœ˜;Lšœ˜L˜L˜—š Ÿ œžœžœžœžœ˜>Lšœa™aLšœžœ˜ Lšœ5˜5Lšœžœ˜Lšœ)˜)Lšœ ˜ Lšœ:˜:šžœžœžœž˜'Lšœ˜Lšœ˜Lšœ˜Lšœ+˜+—Lšžœ˜Lšœ:˜:Lšžœ8˜>Lšœ˜—š Ÿ œžœžœžœžœ˜=Lšœ žœ˜Lšœ˜Lšœ*˜*Lšœ˜Lšœ˜Lšœ4˜4Lšœ4˜4Lšœ4˜4Lšœ4˜4Lšœ2˜2Lšžœ˜ Lšœ˜—š Ÿœžœžœžœžœ˜GLšœ5˜5Lšœžœ˜Lšœ˜Lšœ!˜!šœ.˜.Lšœ3™3—Lšœ?˜?šžœžœžœž˜'Lšœ˜Lšœ0˜0—Lšžœ˜Lšžœ8˜>Lšœ˜—š Ÿœžœžœžœžœ˜CLšœ'˜'Lšœžœ ˜Lšœ.˜.Lšœ/˜/Lšžœ8˜>Lšœ˜—š Ÿ œžœžœžœžœ˜?Lšœ5˜5Lšœžœ˜ Lšœ ˜ Lšœ!˜!Lšœ˜Lšœ!˜!Lšœ^™^LšœA˜ALšœS˜Sšžœžœžœž˜'Lšœ˜Lšœ˜Lšœ0˜0—Lšžœ˜Lšžœ8˜>Lšœ˜—š Ÿ œžœžœžœžœ˜HLšœ8˜8Lšœa™aLšœ#žœ˜DLšœ ˜ LšœV˜VLšœ:˜:šžœžœžœž˜$Lšœ˜Lšœ˜Lšœ˜Lšœ˜Lšœ˜Lšœ2˜2—Lšžœ˜Lšžœ8˜>Lšœ˜—L˜šŸ œžœžœžœ˜5Lšžœ˜Lšœ˜L˜—šŸ œžœžœžœ˜1Lšžœ˜Lšœ˜L˜—šŸœžœžœžœ˜7Lšžœ˜$Lšœ˜L˜—šŸ œžœžœžœ˜3Lšžœ˜Lšœ˜—L˜Lšžœ˜—…—ςΔ