1

First of all, let me make it clear that I don't know much about programming. So after I got that out of the way, thanks for reading my question.

So what I currently want to cram into my little C# programm is the following:

  • Draw a line from pA to pX
  • Draw a curve from pX to pY
  • Draw a curve from pY to pZ
  • Draw a line from pZ to pD

My problem with this is the following:

How on earth do I "switch" from a line to a curve, to another curve and then back to a line in C#?

I'd be really happy if anyone could help me with this.

Greetings from Belgium,

-g2609

  • 2
    which framework? winforms, WPF, the web? show the code you've written so far, and describe the problems with it. – Cee McSharpface Nov 25 '18 at 16:26
  • In general, I only need the x and y coordinates between points. It's for controling a Robot. – Giebels2609 Nov 25 '18 at 16:28
  • a line is just an edge case of a curve. it does not matter if you connect line-line, curve-line or curve-curve. anyway, we need to know a bit more about input and expected output to help here. here is a [recent answer](https://stackoverflow.com/a/52433936/1132334) showing how a graphics library can be used to get a list of points from a path (which in turn may consist of a sequence of lines/curves, which are just drawn one after the other – Cee McSharpface Nov 25 '18 at 16:30
  • Ok, didn't know that. So basically I will tell the robot the start position, the end position and "weight points" and how many steps it should take from start to end. As output, I need xy coordinates for each step – Giebels2609 Nov 25 '18 at 16:32
  • 1
    don't forget the Z coordinate, its not discworld :) – Cee McSharpface Nov 25 '18 at 16:38
  • Thanks for thinking about that, however, for what I'm doing I only need xy, not z. – Giebels2609 Nov 25 '18 at 16:39
  • ok. I figured that was what "pZ" might mean in "... curve from pY to pZ" – Cee McSharpface Nov 25 '18 at 16:40
  • No, pY and Pz are both points, both on the same plane but with different x and y coordinates. Any idea how to go from line to curve? – Giebels2609 Nov 25 '18 at 17:00
  • The real question is in the 1st comment. you may need to study graphicspath with both the pathpoints and the pointtypes arrays. – TaW Nov 25 '18 at 17:27

1 Answers1

0

Seems you want to provide smooth connection of line segments and curves.

Note that Bezier curves at the end points have direction (tangents) to control points. So just put control points at the continuation of straight segments. Distance from the enpoints to the control ones is responsible for curvature. Try to use values like distXY / 3 to start.

For curve-curve connection you have to define some rule. For example, define tangent direction (and maginute again). If you need smooth curve chain, consider interpolation splines - this approach calculates cubic curves parameters for all curves and provides continuity.

Pseudocode for line A-X, cubic Bezier X-Y, line Y-Z.

 VecAX = X - A
 uAX = (VecAX.X / VecAX.Length, VecAX.Y / VecAX.Length)
 curveXY.P0 = X
 curveXY.P1 = X + uAX * VecAX.Length / 3
 curveXY.P2 = Y - uXZ * VecXZ.Length / 3
 curveXY.P3 = Y
MBo
  • 77,366
  • 5
  • 53
  • 86