0

Sorry if this has been asked before, but I couldn't find a valid response or a response I could understand

Currently I have a code that draws a line from a Joint to Joint in the Kinect, this forms the Bone:

  drawingContext.DrawLine(drawPen, jointPoints[jointType0], jointPoints[jointType1]);

enter image description here

In the picture aboe it shows Parallel lines joining from circle to cirlce, Can someone please explain to me or show me to create these lines?

  • If question is about game development, you may get better [help here](http://gamedev.stackexchange.com/) – Sriram Sakthivel Apr 22 '15 at 19:36
  • Not game development but I am developing a programme which is supposed to track a users joints, however I am having trouble doing simple things like what the picture shows. For instance I just need to know how to draw parallel lines like shown in the picture and also the number above the circle. – ShatteredPheonix Apr 22 '15 at 19:37

1 Answers1

4

If you have a line from point p0 to point p1, and want to create a parallel line / offset line, you need to use either trigonometry or vector math.

To do it using vector math:

  • Find the direction vector of the line
  • Find a vector perpendicular to that
  • Use the perpendicular vector to offset p0 and p1

Pseudo code:

Vector vLine = ( p1 - p0 ).Normalized();
Vector vPerp = new Vector( -vLine.Y, vLine.X );
Point newp0 = p0 + vPerp * offset distance
Point newp1 = p1 + vPerp * offset distance
DrawLine( newp0, newp1 );

Reverse the offset or negate vPerp to get a line on the other side. How you do this depends on what you have available. System.Windows.Vector and System.Windows.Point should work fine since you're using WPF.

If you are interested in what's going on here in more detail, get your googling on and search for vector math or linear algebra.

Chris
  • 5,442
  • 17
  • 30
  • Oh thanks I will try this when I get back home, and yea I understand for the most part, since I had to use vector maths to calculate angle between the joints. My only other question is how the hell do I put a number like that above the circle? – ShatteredPheonix Apr 22 '15 at 20:07
  • @ShatteredPheonix Simply take the position of the joint and offset it a bit. Pseudo: `DrawText( text, p0 + new Point( 0, -10 ) )` – Chris Apr 22 '15 at 20:12
  • @ShatteredPheonix You'll also notice later on that if you want to get results exactly like that picture you'll also need to trim the ends of the lines to the circles..! – Chris Apr 22 '15 at 20:43
  • yea I think I have a method for that in mind, but I needed to achieve this effect for a project I'm doing. If I can't get it work I'll be posting more questions, it's my first time using wpf and Xaml – ShatteredPheonix Apr 22 '15 at 20:46
  • I managed to get the parallel lines thanks you but my method for rounding them off at the outer circle didn't work – ShatteredPheonix Apr 22 '15 at 22:00
  • @ShatteredPheonix Google for an algorithm for intersecting a line with a circle. You'll either find no intersection, one (if it's tangential) or two. When you find two, pick the one closest to the other joint position and you should be good to go. – Chris Apr 23 '15 at 06:18