Hello,

i want to create a dynamic triangle in WPF. My code is nearly working, but i have a small problem. I have the following scenario: The User clicks on my GUI, now he can move the mouse while the left button is pressed. When he moves it, it creates a triangle. The orthocentre of the triangle is (should be) always where the left mouse button was first pressed. The height point is always where the cursor is at the moment. The angle in this point is (in this case) always 40°.

The problem is, that the orthocentre is at that point where it should be just at to exact angles times in my circle.

I think something of my algorithm is a bit wrong, but i can't imagine what. Maybe you guys can give me some input.

Point aPoint = new Point();
Point bPoint = new Point();
Point cPoint = new Point(e.GetPosition(Canvas1).X, e.GetPosition(Canvas1).Y);
Point helpPoint = new Point(xPosition, yPosition);
const double cameraAngle = 20 * Math.PI / 180;
double m1 = this.CalculateMWithTwoPoints(cPoint.X, cPoint.Y, helpPoint.X, helpPoint.Y);
double m2 = 1/m1;
double b2 = this.CalculateB(helpPoint.X, m2, helpPoint.Y);
double m3 = Math.Tan(angle + cameraAngle);
double b3 = this.CalculateB(cPoint.Y, m3, cPoint.X);
double xA = this.CalculateX(m2, m3, b2, b3);
double yA = this.CalculateY(m3, xA, b3);
aPoint.X = xA;
aPoint.Y = yA;
double m4 = Math.Tan(angle - cameraAngle);
double b4 = this.CalculateB(cPoint.Y, m4, cPoint.X);
double xB= this.CalculateX(m2, m4, b2, b4);
double yB = this.CalculateY(m4, xB, b4);
bPoint.X = xB;
bPoint.Y = yB;
polygon.Points = new PointCollection { aPoint, bPoint, cPoint};

private double CalculateMWithTwoPoints(double x1, double y1, double x2, double y2)
{
return (y2 - y1) / (x2 - x1);
}
private double CalculateB(double y, double m, double x)
{
return -(m * x - y);
}
private double CalculateY(double m, double x, double b)
{
return m * x + b;
}
private double CalculateX(double m1, double m2, double b1, double b2)
{
return (b1 - b2) / (m1 + m2);
}

A helpful Link : http://www.mathopenref.com/coordpolygonarea.html

http://www.mathopenref.com/indexpage.html (See Triangle Here)

Could you give one or two examples which shows what you explained, what happens and what you want to happen ?

In your code I don't see when you take the orthocentre-coordinates. It should be only at the MouseClick-Moment and not during the whole MouseDown-time ...

Here is an example how it should look:

http://www.mathelounge.de/?qa=blob&qa_blobid=9135849813851033220

Here is an example how it should NOT look:

http://www.mathelounge.de/?qa=blob&qa_blobid=4668010827737964515

Here's my german explanation, I've seen you're german, so maybe I explained it better there.

http://www.mathelounge.de/275282/punkte-gleichschenkligen-dreiecks-einem-punkt-allen-winkeln

When looking to your Screenshots : where are the Coordinates saved in the Moment of MouseClick ? In the Center of the circle ? Somewhere on the line from the triangle to the center of the control ?

To which point should they correspond ? to the Center of your Control ?

Is it a kind of AngleEditor you want to create ? Or a Kompass ?

Okay i should explain the use case:

The User has a 2D-Map. This 2D-Map can be synchronized in a 3D-World where the user can move around with a camera. I want to create a function where the user can click anywhere on the map on a point he wants to see (that's the centre of the circle) in the 3D-World and by moving the mouse he can define his distance to that point and the angle in the 3D-World from where he's looking. The triangle shows the user exactly his field of vision to the point.

I hope this made it a bit more clear to you