Suppose I have a (kinked) line, for example

2-x==y && x< 1
3-2x == y && 1.5>=x>= 1

I want to take this kinked line and represent discretize it (i.e. I want to display points along this line)

I can do this with discretize region, for example

r=ImplicitRegion[2-x==y && x<1 , {x,y}];
r2=ImplicitRegion[3-2x == y && 1.5>=x>= 1,{x,y}];

This will give me a graphic of the line and some discrete points (I would prefer to not have the line included here, but that's not too important)

  • How can I show how these points are being determined?
  • How can I control how these points are being determined?

My guess is that there is a mesh function or something similar, and if so I could control how the points are being determined by specifying the mesh, but I could not figure this out.

Alternatively, perhaps it is better to use something like MeshRegion?

An explanation of what I want to do:

I want to take a function ( a kinked line in this case, but the function doesn't really matter).

Then, I want to construct a grid consisting of points generated by the intersection of vertical and horizontal grid lines, spaced at intervals of size $d$

Next, I want to find the the intersection of these points and the function, and display only these points, as well as the underlying grid that generated them

  • (I'm okay not displaying the grid if it gets in the way of visualization, as long as I can separately generate a graphic that shows the grid that was used. Basically, I want to be able to visualize how the points are selected)

An answer doesn't need to use the method I try above. I'm sure custom code can be written to do this. or maybe a mesh could be used where the mesh cells are point (I don't know enough about meshes to say whether that's a viable approach or not)


Heres a rough solution of mine. Feedback and suggestions are very welcome

*this function makes a grid*)


(*the intercept is written in such a form below because I want the intercept to be
such that the two lines meet at .7*10 *)

kinkedfunction[x_]:=Module[{botslope=2,topslope=1},\[Piecewise] 3 +topslope*(.7*10)-topslope*x  x<=.7*10
17-botslope*x   x>.7*10


discretefunction[xmax_, xspace_, func_] := {#, func[#]} & /@ 
   Range[0, xmax, xspace];

(*This function finds the points that the discretized function and \
the grid have in common *)
addpts[ptslist_, gridpts_] := 
  Module[{n = #[[1]]*100 + 1}, 
    If[MemberQ[Round[ gridpts[[1000*(n - 1) + n ;; 1000*n + n]], .01],
       Round[#, .01]], AppendTo[ptslist, #], 
     AppendTo[ptslist, Nothing]]] &;

Where a couple comments are in order:

  • the grid is written with flatten because there are some issues with the approach that I need to remedy. (and hence also the rounding in addpts function

  • It is probably better to not use module when defining the piecewise function, and to just put the slopes as arguments. I couldn't decide which way to go

  • Instead of finding the common points with a pure function, I could perhaps have just used a regular function. I'm not sure about the benefits and downsides of one approach vs the other?
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.