<< Chapter < Page Chapter >> Page >

The corresponding SVG code

The Java code in Listing 9 causes the four rect elements shown in Listing 10 to be created in the output SVG code.

Listing 10 . SVG code to draw more rectangles.
<rect fill="none" stroke="black" stroke-width="1" x="90" y="405" width="630" height="90"><title>rectangle</title></rect><rect fill="none" stroke="black" stroke-width="1" x="585" y="495" width="45" height="225"><title>rectangle</title></rect><rect fill="none" stroke="black" stroke-width="1" x="180" y="225" width="180" height="180"><title>rectangle</title></rect><rect fill="none" stroke="black" stroke-width="1" x="450" y="225" width="180" height="180"><title>rectangle</title></rect>

You already know all about drawing rectangles, so no further explanation of the code in Listing 9 and Listing 10 should be needed.

Draw a polygon

The next task is to draw a triangular object that represents Mass C in the drawing. This is accomplished by the Java code in Listing 11 that causes a polygon, in the shape of a triangle, to be drawn.

Listing 11 . Draw a polygon.
//Draw Mass A Element massA = SvgLib21.makePolygon(svg, ns,"polygon", new double[]{ 7.5, 1.0,//x-y coordinate pair9.5, 1.0,//x-y coordinate pair 8.5, 2.5 //x-y coordinate pair});

What can you modify?

You can modify the following items in the Java code shown in Listing 11 .

  • The name of the object ( massA in Listing 11 ).
  • The title ( "polygon" in Listing 11 ).
  • The number of x-y coordinate pairs in the list of x-y coordinate pairs along with the values of the coordinates.

What is a polygon?

In SVG terminology, a polygon is a drawing that consists of a series of points in two-dimensional space connected by line segments. An additional linesegment is automatically drawn from the last point to the first point. For example, triangles, pentagons,and hexagons are polygons.

What is a polyline?

In SVG terminology, a polyline is exactly like a polygon except that a line segment is not automatically drawn to connect the last point to the first point.

There are no polyline elements in this example drawing, but there is one in the program for a different drawing shown in Listing 27 . The Java code for drawing a polyline is the same as the Java code for drawing apolygon. The difference between the two occurs when the SVG processor draws the shapes and either does, or does not automatically connect the last point to thefirst point.

The most versatile shape

The polyline is the most versatile of all of the basic shapes. With enough patience, it can be used to draw any shape that can be drawn with curved lines. Todraw a curved line using polyline elements, approximate it using a large number of short line segments. For example, polyline elements provide anideal mechanism for drawing the kind of shapes that are commonly referred to as "curves" in math, physics, and engineering courses. By this, I mean a drawingthat shows how a dependent variable behaves relative to an independent variable.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Accessible physics concepts for blind students. OpenStax CNX. Oct 02, 2015 Download for free at https://legacy.cnx.org/content/col11294/1.36
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Accessible physics concepts for blind students' conversation and receive update notifications?

Ask