Using VC to draw logarithmic coordinate system

Source: Internet
Author: User
Tags dashed line pow

Using VC to draw logarithmic coordinate system

Objective: To draw the logarithmic coordinates with any frequency as the starting point and at any frequency as the end point, and to scale the coordinates arbitrarily.

Implementation method:


= = = "Update 2013-12-18": =========================================================

It's a stupid way to find out the way you used to be today. In fact, as long as you know the x coordinates of any two points and its corresponding frequency F, you can determine the 3rd of the frequency of the coordinates 3rd, or based on the 3rd coordinates to determine the frequency of the point. The essence of the logarithmic coordinates of the individual senses is that after the logarithm of the frequency, the coordinate map becomes a linear coordinate, that is, the screen coordinate x can be regarded as a linear function of log (f).
Given three points (x0,f0), (X1,F1), (X2,F2), where x is the x-coordinate, F is the corresponding frequency, there is a corresponding relationship (x2-x0)/(x1-x0) = (log (F2)-log (F0))/(log (F1)-log (f0)) = log (f2/f0 )/log (f1/f0), you can obtain X1=log (f1/f0)/log (f2/f0) * (x2-x0) +x0, and log (f1) = 1/c* log (f2/f0) +log (F0), where c= (x2-x0)/(x1-x0 )。
According to these two formulas, write two functions, one is based on the frequency of the x coordinates, one based on the x-coordinate frequency, and then specify the position of the axis, you can easily draw the logarithmic coordinate system. =====================================================================================

The following is obsolete and is for informational purposes only.


1. Definition

Standard frequency: The corresponding frequency point with a frequency value of 10N, wherein n=...-2,-1,0,1,2,3 ..., unit MHz. such as 0.01MHZ, 0.1MHz, 1MHz, 10MHz, 100MHz, etc. are standard frequencies.

2. Train of Thought

First find the standard frequency, draw the standard frequency line, and then draw the other frequency lines according to the standard frequency.

3. Realize

(1) Mathematical basis of logarithmic coordinate system

In the logarithmic coordinate system as shown in the figure:

From this, if you know the coordinates of the three points in the above figure, you can find the coordinates of another point.

(2) Find the code that starts | terminating the standard frequency:

Double stdstartfreq,stdstopfreq;//standard frequency starting point, termination point

Format standard Start frequency

for (int i=0;i<7;++i)

{

if (Startfreq==pow (double) 10,i-2)

{

Stdstartfreq=startfreq;

Break

}

else if (Startfreq>pow (double) 10,i-2) && Startfreq<pow ((double) 10,i-1)

{

Stdstartfreq=pow (double) 10,i-1);

Break

}

}

Format standard termination frequency

for (int i=0;i<7;++i)

{

if (Stopfreq==pow (double) 10,i-2)

{

Stdstopfreq=stopfreq;

Break

}

else if (Stopfreq>pow (double) 10,i-2) && Stopfreq<pow ((double) 10,i-1)

{

Stdstopfreq=pow (double) 10,i-2);

Break

}

}

The starting standard frequency is the first standard frequency greater than the starting frequency; the termination standard frequency is the last standard frequency less than the termination frequency.

For example: If the starting frequency is 1.9MHz, the termination frequency is 201MHz, then the starting standard frequency is 10MHz, the termination standard frequency is 100MHz; If the starting frequency is 1.9MHz and the termination frequency is 20.1MHz, then the starting standard frequency is 10MHz and the termination standard frequency is 10MHz; If the starting frequency is 1 9MHz, the termination frequency is 2.01MHz, then the starting standard frequency is 10MHz, the termination standard frequency is 1MHz.

(3) Three kinds of cases

① starting frequency ≤ starting standard frequency < terminating standard frequency ≤ termination frequency

In this case, first draw the start | stop standard frequency line. For the portion between the starting frequency and the starting standard frequency, draw a dashed line from the starting standard frequency to the starting frequency; for the part between the termination standard frequency and the termination frequency, draw the dotted line from the terminating standard frequency to the terminating frequency; for the portion between the starting standard frequency and the terminating standard frequency, first find the standard frequency between the two , and then draw the dotted line according to the standard frequency (including the start | Stop standard frequency).

② Starting frequency < starting standard frequency = termination standard frequency < termination frequency

This is a special case of the first case. Because the starting standard frequency = terminate the standard frequency, there are only two situations in the first case to draw a dashed line.

③ Termination Standard Frequency < start frequency < termination frequency < starting standard frequency

In this case, the terminating standard frequency is first identified and the dotted line between the starting frequency and the termination frequency is incremented according to the terminating standard frequency.

4, other issues

(1) Refinement interval

Because the interval of the same frequency segment of logarithmic coordinates is different, the 10~20mhz interval is different from that of the 80~90mhz, the former is greater than the latter; In addition, considering the enlargement of the coordinate system, such as 200mhz~300mhz frequency segment, the whole coordinate system has no dotted line, only horizontal lines, It is difficult to make a rough judgment of the frequency of a point in a test curve. Therefore, for the larger interval, should be refined.

The method is to make use of the proportion of the coordinate axis of the adjacent two dotted lines, and it is necessary to refine it if it is larger than a certain number. Because the interval is very small, considering that the refinement of the interval can not affect the overall logarithmic coordinate effect, so the refined vertical line with a gray dotted lines, and the interval is divided into different grades, different grades draw different gray dotted lines.

(2) Coordinate marking

The coordinate annotation also uses the proportion of the coordinate axis of the adjacent two dotted lines to judge, which is larger than a certain value before marking.

The

  source code is as follows: "//  draw logarithmic coordinates
void  cemcview::D rawlogcoords (CDC *  pDC,  double  startfreq ,  double  stopfreq)
... {
    CString note;
    CRect rect;
    this->getclientrect (&rect);
    origin_x=rect.left+rect. Width ()/10;    //  coordinate origin x coordinate
    origin_y=rect.bottom-rect.height ()/10;    //  coordinate origin y-coordinate
    coord_top=rect.top+rect. Height ()/10;    //  coordinate system highest point y-coordinate
    coord_right= Rect.right-rect.width ()/10;    //  coordinate system most-right x-coordinate

    pDC-> MoveTo (origin_x,origin_y);
    pdc->lineto (origin_x,coord_top);    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.