Geom Module

The Geom module contains

  1. Geometry. Immutable classes for points, lines and shapes. These classes build on the Array based collections from the Util module.
  2. Colour class. A 32 bit integer class that can be built from rgba and named values.
  3. Graphic primitives. Immutable classes for fills, draws and active elements based on the geometry classes.
  4. Compound Graphics. Again immutable classes. Useful for selection and placing.
  5. Geometric transformations on both the geometric and graphical elements, preserving maximum type information.
  6. An abstract canvas on which to display the graphic elements. Concrete implementations for JavaFx and HtmlCanvas, allowing applications to be created with minimal platform specific code. The abstract canvas api could be implemented on DirectX or OpenGL, but this would require significantly more work than for the ScalaFx canvas or the Html Canvas.
  7. Conversion of Graphic classes into SVG, gving an alternative target and greater flexibility.
  8. Web library. Classes for XML, HTML, CSS and simple JavaScript functions. These pages have been generated using this.
  9. 3D geometry as well as distance unit classes as opposed to scalars for 1D, 2D and 3D. Basic 3D Graphics will be provided, but currently there is no attempt to provide any kind of 3D or physics engine, although a 3D implementation for canvas is entirely possible.
  10. Series of lessons / tutorials in geometry and graphics.
  11. Earth geometry. This is for Earth maps. Allows the manipulation of latitude and longitude allowing free conversionbetween them and 2D and 3D coordinates.

Polygons

Polygons are used a lot in this module and in modules that use this module. So it is important to establish conventions or defaults. The vertices of an N sided polygon are numbered from 0 to n - 1. With the vertex 0 appearing at 12 o'clock or 00 hundred hours as in the dodecahedron below. Vertex 1 appears at the 1 o'clock position, vertex 2 at the 2 o'clock position etc. The middle of side 0 is at 12.30 or 00.30 hours, the middle of side 1 is at 01.30 hours etc.

Centre V0 V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 Sd0 Sd1 Sd2 Sd3 Sd4 Sd5 Sd6 Sd7 Sd8 Sd9 Sd10 Sd11

I've included the Scala code below both for the above diagram. If you check the html source code for this web page you will see that it is pretty succinct compared with the generated SVG code. The code is in small font and is not type annotated so it is not intended as a tutorial, but just to give an idea of possibilities. It is only the last line that creates the SVG. The rest of the code could be used in an HTML or a JavaFx canvas.

val width: Int = 250
val polyColour: Colour = DarkGreen
val dodec1: DoDeclign = DoDeclign(width)
val dodec2 = dodec1.draw(polyColour)
val circ = Circle(width * 2).draw()
val verts = dodec1.vertsIFlatMap{ (pt, i) => pt.textArrowToward(Pt2Z, "V" + i.str) }
val sides = dodec1.sidesIFlatMap{ (sd, i) => sd.midPt.textArrowAwayFrom(Pt2Z, "Sd" + i.str, colour = polyColour) }
val cen = Pt2Z.textAt("Centre")
val clock = RArr(dodec2, circ, cen) ++ verts ++ sides
val svg1 = HtmlSvg(dodec1.boundingRect.addMargin(svgMargin), clock, RArr(CentreBlockAtt))

If there is no vertex at the 12 o'clock / 00 hundred hours postion as in the rectangle below vertex 0 is the first vertex clockwise of 12 o'clock. The other vertices then follow clockwise. The last vertex being immediately anti clockwise of 12 o'clock.

Centre V0 x = 200; y = 125 V1 x = 200; y = -125 V2 x = -200; y = -125 V3 x = -200; y = 125 Sd0 Sd1 Sd2 Sd3

The positions of the vertices have been shown above. Note that the positions are speciified relative .

Circles and Ellipses