0

I made a speedometer control My controller has a property called Angle that changes the shape of my speedometer (180 for Complete Circul, and so on...)

With the help of a converter, I can move the speedometer correctly

// values[0] = Angle
// values[1] = Value

var startAngle = System.Convert.ToDouble(values[0]) * -1;
var endAngle = startAngle + (((double)values[1]) * 2);
return endAngle;

Now I want to have a property called Maximum, And if the user sets it to 50, even if my circle is 360 degrees, the whole circle will be full with 50 values.

I used the following code but unfortunately it does not work properly

return value * angle / maximum;

also this is my arc

<x:Arc StartAngle="{Binding Angle, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource Positive2Nagative}}" EndAngle="{Binding Angle, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>   

 

UPDATE:

this code:

//a = s * A / max
value * angle / maximum;

Compile to this:

enter image description here

<loc:speedometer Angle="120" MaximumValue="50" Value="{Binding ElementName=sld, Path=Value}"
                           />

UPDATE 2:

i fixed problem with this code

return ((value * angle / maximumValue * 2) - angle);
Atena
  • 109
  • 2
  • 9
  • Is your question [how to pass parameter into converter](https://stackoverflow.com/q/37459122/1997232)? – Sinatr Aug 14 '20 at 11:30
  • @Sinatr no i want convert value to angle with maximum property – Atena Aug 14 '20 at 11:35
  • 1
    This is not an [mre] - now way to help you ... – Patrick Artner Aug 14 '20 at 11:40
  • You mention 360 degrees and 180 and somehow your startangle is negative. What is your speedo supposed to look like? What angle is zero, what angle is maximum equivalent to? – Andy Aug 14 '20 at 11:46
  • @Andy Arc Control has 2 property called StartAngle and EndAngle If the startAngle is 0 and the endAngle is 360 we have a complete circle and If the startAngle is -180 and the endAngle is 180 we have a complete circle again also If the startAngle is -120 and the endAngle is 120 we have almost a semicircular shape – Atena Aug 14 '20 at 12:01
  • You might want to describe better what you mean by `-120` degrees. Normally a negative angle refers to the angle created from a horizontal radius at `0` degrees (with the center point on the left side of the radius), moving clockwise around a circle. So the right-angle formed by a `90` degree angle is exactly the same shape as a `-270` degree angle; it just means we got there going clockwise around the circle instead of counter-clockwise. Therefore, a speedometer shaped like a semi-circle would normally be described as going from `180` (`0` mph) to `-360`. – Rufus L Aug 14 '20 at 12:24

2 Answers2

0

I think you are looking for the following:

Given an angle a, the equivalent value s, considering A degrees repesents the maximum value max, is:

 s = a * max / A

Or what is pobably more useful, the angle a which reprenets a given speed s in a A degree speedometer with a maximum speed max is:

a = s * A / max

That said, I'm not really sure how your speedometer works. At first you talk about a 180º gauge and then you start talking about a full 360º one. Either way, A is either 180 or 360.

InBetween
  • 32,319
  • 3
  • 50
  • 90
  • Arc Control has 2 property called StartAngle and EndAngle If the startAngle is 0 and the endAngle is 360 we have a complete circle and If the startAngle is -180 and the endAngle is 180 we have a complete circle again also If the startAngle is -120 and the endAngle is 120 we have almost a semicircular shape – Atena Aug 14 '20 at 12:06
0

You're using a very strange notation for this.

Let's call a change in value of 1 a step. So 50 km/h maximum means 50 steps.

You want 50 steps between the start and end.

Your first task is to work out angle per step.

For that you need to know the angle the entire arc will go through.

If the start is always over there on the left of the vertical line then it's always negative.

Hence you want -1 * start for the left number of degrees offset from vertical.

The right is easy it's just end.

Hence (-1 * start) + end = totalArc degrees

That gives you how many degrees the 0 to max covers.

Let's call the thing you're representing speed. Because angle is a very very bad name for a variable in a calculation which is all about angles.

totalArc / maximum gives the value in degrees of each step in our speed.

Hence you want (totalArc / maximum) * speed.

That gives you the angle between the start and where the speed indicator should go to.

You will then have to work out what that means in terms of your display.

I would suggest the simplest is to rotatetransform whatever does the red stuff so 0 angle matches the start. Maybe you're already doing that though.

Andy
  • 11,864
  • 2
  • 17
  • 20