Next Page Contents

plot::Curve2d -- graphical primitive for a two-dimensional curve

Introduction

plot::Curve2d([x, y], t = a..b) represents a plot of the curve defined by t -> (x(t); y(t)) with t in [a,b].

Creating Elements

plot::Curve2d([x, y], t = a..b <, option1, option2...>)

Parameters

x, y - arithmetical expressions in t
t - identifier
a, b - arithmetical expressions
option1, option2, ... - plot option(s) of the form OptionName = value

Related Domains

plot::Curve3d, plot::Function2d, RGB

Related Functions

plot, plot2d, plot::copy

Details

Option: Discont =

value

Option: RealValuesOnly =

value

Operands

An object of plot::Curve2d consists of two operands. The first operand is the term of the curve specified as the list [x, y]. The second one is the parameter of the curve and its range in the form t = a..b.

Important Operations

Operands of a curve primitive can be accessed either using the system function op, the index operator [ ], or using the attributes described above. For example, if curve is such an object, then the calls op(curve,1), curve[1] and curve::term return the list [x, y].

Via curve[1] := [new_x, new_y] or curve::term := [new_x, new_y], the term of a curve primitive can be changed.

See the methods "op", "_index", "set_index" and "slot" below.

Use the slot operator :: to get or set plot options of such objects afterwards, i.e., when they have been created. For example, if curve is such an object, then curve::Color := RGB::Red changes the color of the curve primitive curve to red.

Result of Evaluation

Evaluating an object of type plot::Curve2d returns itself.

Function Call

Calling an object of plot::Curve2d as a function yields the object itself, regardless of the arguments. The arguments are not evaluated.

Entries

defaultOptions

is a table of plot options for curve primitives and their default values. Each entry has the form OptionName = default_value.

When an object of the domain plot::Curve2d is created, then a copy of this table is stored under the attribute options (see the table of attributes above), where those options are added and replaced, respectively, which are given by the (optional) parameters option1, option2... of the creating call (see ``Creating Elements'' above).

Plot options, which are not contained in the table stored under the attribute options will not be included in the plot data of the object created by the method "getPlotdata" (see below).

For those options, the corresponding default value either is set by a graphical scene, if the option also exists as a scene option (such as the option PointWidth), or it is internally set by the function plot2d which is used to plot the object. See the table of plot options above, which gives a summary of the available plot options for curve primitives and their default values. See example 2.

To change the default value of some plot options, the option name and its default value may be added to the table "defaultOptions", or replaced by a new value, respectively.

optionNames

is a set of the available option names for plots of two-dimensional curves.

Method _index: indexed access to the operands of a curve primitive

Method dimension: dimension of a curve primitive

Method getPlotdata: create the plot data of a curve primitive

Method nops: number of operands of a curve primitive

Method op: extract operands of a curve primitive

Method set_index: set operands of a curve primitive

Method slot: read and write attributes and plot options

Method checkOption: check a plot option

Method copy: create a copy of a curve primitive

Method modify: modify a copy of a curve primitive

Method print: print a curve primitive

Example 1

The following call returns an object representing the graph of the unit circle:

>> c := plot::Curve2d([sin(t), cos(t)], t = 0..2*PI)
               plot::Curve2d([sin(t), cos(t)], t = 0..2 PI)

To plot this curve in a graphical scene, call plot:

>> plot(c)

Plot options of the curve can be given as additional parameters in the creating call, such as increasing the width of the lines of a graph and plotting the graph in red color:

>> c2 := plot::Curve2d([sin(t), cos(t)], t = 0..2*PI, 
     Color = RGB::Red, LineWidth = 50
   )
               plot::Curve2d([sin(t), cos(t)], t = 0..2 PI)
>> plot(c2)

To change default values of some scene options, pass the scene options to the function plot as additional arguments. For example, change the scaling of the plot and increase the number of ticks on both axes:

>> plot(c2, Scaling = Constrained, Ticks = [10,10])

See the help page of plot::Scene for available scene options.

Example 2

If a curve primitive is created, values of some plot options of the created object can be read, or replaced by new values.

To illustrate this, we create the following curve:

>> c1 := plot::Curve2d([t*cos(t), t*sin(t)], t = 0..4*PI)
             plot::Curve2d([t cos(t), t sin(t)], t = 0..4 PI)

We create a copy of this curve, change some plot options of the copied object, and plot both objects in a graphical scene:

>> c2 := plot::copy(c1): 
   c2::Style := [Points]: c2::Grid := [30]:
   plot(c1, c2)

Plot options, which are explicitely set for a curve primitive, are stored under the attribute options and can be read with the slot operator ::. The plot options for the first created object are:

>> c1::options
                     table(
                       RealValuesOnly = TRUE,
                       Discont = TRUE,
                       Grid = [100],
                       Color = [Flat, [1.0, 0.0, 0.0]]
                     )

These are the default values of some plot options for two-dimensional curve primitives, defined by the entry "defaultOptions" of the domain plot::Curve2d:

>> plot::Curve2d::defaultOptions
                     table(
                       RealValuesOnly = TRUE,
                       Discont = TRUE,
                       Grid = [100],
                       Color = [Flat, [1.0, 0.0, 0.0]]
                     )

When the plot data of a curve primitive is created (calling the method "getPlotdata"), only those plot options are used that are contained in the table c1::options. Here these are:

>> plot::Curve2d::getPlotdata(c1)
      [[Mode = Curve, [t cos(t), t sin(t)], t = [0.0, 12.56637061],
      
         Grid = [100], Color = [Flat, [1.0, 0.0, 0.0]]]]

This means that for any other available plot option not contained in the table c1::options, the default value is either set by plot::Scene, if the option also exists as a scene option, or it is internally set by the function plot2d when plotting the object.

You might wonder why the options RealValuesOnly and Discont are not contained in the plot structure returned by the method "getPlotdata". The options are special options for objects of the domain plot::Curve2d. They are used to determine the plot data of such an object. They are not accepted as valid options for the mode Curve of the plot2d command.

The curve primitive c2 contains the following options:

>> c2::options
                     table(
                       Style = [Points],
                       RealValuesOnly = TRUE,
                       Discont = TRUE,
                       Grid = [30],
                       Color = [Flat, [1.0, 0.0, 0.0]]
                     )

As you see, the option Style was added to this table, and the default value of the option Grid was replaced by the new value [30]. Use delete to remove plot options:

>> delete c2::options[Style]: c2::options
                     table(
                       RealValuesOnly = TRUE,
                       Discont = TRUE,
                       Grid = [30],
                       Color = [Flat, [1.0, 0.0, 0.0]]
                     )

Example 3

In order to illustrate the effect of the option Discont, we create the following curve primitive:

>> c := plot::Curve2d([tan(t), t], t = 0..4*PI)
                  plot::Curve2d([tan(t), t], t = 0..4 PI)

The tangens has singularities at multiplicities of PI/2, which is determined by plot::Curve2d, if the option Discont is set to TRUE. This is the default behaviour of plot::Curve2d:

>> plot(c) 

Setting this option to FALSE causes spurious lines at the singularities:

>> c::Discont := FALSE: plot(c) 

Example 4

If the option RealValuesOnly is disabled, complex arguments produced by the parametrization of the curve lead to runtime errors during the evaluation of the plot:

>> c := plot::Curve2d([sqrt(t), -sqrt(t)], t = -5..5, 
     RealValuesOnly = FALSE
   ): 
   plot(c)
      Error: Non-real values detected (try option RealValuesOnly = \
      TRUE) [plotlib::clip2d_Curve]

Example 5

This example illustrates how to read and write attributes of curve primitives (see the table of available attributes in ``Details'' above).

In example 2, we already used the attribute options, which stores plot options defined individually for a curve primitive and which overrides the corresponding default values set by MuPAD.

The attribute term holds the term of a curve primitive. For example, if curve is an object of plot::Curve2d such as:

>> c := plot::Curve2d([tan(t), t], t = 0..4*PI, Color = RGB::Blue)
                  plot::Curve2d([tan(t), t], t = 0..4 PI)

then c::term returns the list:

>> c::term
                                [tan(t), t]

We plot this curve:

>> plot(c) 

Because the attribute term has the ``write'' property, you can change the value of this attribute as follows:

>> c::term := [1/cos(t), t]: plot(c)

The value of term must be a list of two arithmetical expressions, otherwise an error message is issued.

An example of a ``read-only'' attribute is the attribute plotdata. It stores the plot data of a curve primitive in a plot2d conforming syntax. However, the value of this attribute should only be used if the attribute refreshPlotdata has the value FALSE.

For example, if we create a new curve primitive, then the value of plotdata is the empty list:

>> c2 := plot::Curve2d([t^2, t^2], t = -5..5):
   c2::plotdata
                                    []

and refreshPlotdata signals that the plot data must be created:

>> c2::refreshPlotdata
                                   TRUE

A call of the method "getPlotdata", which is caused by plotting the curve, for example, creates the plot data of a curve primitive:

>> plot::Curve2d::getPlotdata(c2)
                        2   2
      [[Mode = Curve, [t , t ], t = [-5.0, 5.0], Grid = [100],
      
         Color = [Flat, [1.0, 0.0, 0.0]]]]

This plot data is the new value of the attribute plotdata, and refreshPlotdata was set to FALSE. Thus, an unnecessary rebuilding of the plot data of this object can be avoided by reading the value of plotdata:

>> c2::refreshPlotdata(c2), c2::plotdata
                               2   2
      FALSE, [[Mode = Curve, [t , t ], t = [-5.0, 5.0],
      
         Grid = [100], Color = [Flat, [1.0, 0.0, 0.0]]]]

Any change of a plot option or an attribute of the curve primitive sets the value of refreshPlotdata to TRUE:

>> c2::Color:= RGB::Black: c2::refreshPlotdata(c2)
                                   TRUE

This means that the value of plotdata is not longer valid, and the method "getPlotdata" must be called to rebuild the plot data of c2.

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000