0
$\begingroup$

Write a function that creates a new figure (a new broken line) out of a given broken line. It would take as parameter a list of (max) 20 points representing the closed broken line. The output must be a plot with the two figures in different colors.

The new figure is created by connecting midpoints of consecutive segments of the figure.

Suggestion. Keep the coordinates of the randomly generated points in a symmetrical interval, for simplicity.

Observation. A closed broken line is a figure made of segments such that each segment's left endpoint is connected to another segment's right endpoint.

Given four points, the output should be similar to this:

enter image description here

$\endgroup$

closed as off-topic by corey979, MarcoB, José Antonio Díaz Navas, Sjoerd C. de Vries, bbgodfrey Mar 29 at 15:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – corey979, MarcoB, José Antonio Díaz Navas, Sjoerd C. de Vries, bbgodfrey
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ What have you tried? This looks like a homework problem and we generally like to see what you've tried before we try to help. $\endgroup$ – b3m2a1 Mar 28 at 18:19
  • $\begingroup$ ListLinePlot might be of interest. $\endgroup$ – Henrik Schumacher Mar 28 at 18:23
  • 1
    $\begingroup$ @HighPerformanceMark before the edit it was $\endgroup$ – b3m2a1 Mar 28 at 21:13
  • $\begingroup$ This is not a do-my-homework site. $\endgroup$ – Daniel Lichtblau Mar 29 at 15:43
3
$\begingroup$

I would typically not answer this kind of questions, but this was interesting to me:

BlockRandom[SeedRandom[5348]; pts = RandomReal[{-2, 2}, {4, 2}]];

Graphics[{
    FaceForm[None],
    EdgeForm[{Thick, Blue}], Polygon[pts],
    EdgeForm[{Thick, Red}], Polygon[Mean /@ Partition[pts, 2, 1, {1, 1}]]
  },
  Axes -> True
]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Usually, I use ListCorrelate[] instead of Mean[] + Partition[], but this works. $\endgroup$ – J. M. is away Mar 29 at 1:13

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