The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 data selection
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

injector

USA
3 Posts

Posted - 08/11/2005 :  4:13:38 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin):v7.5776
Operating System:win2000

I have 50000 data points (x,y) in two columns. Now I want to draw an ellipse that could contain certain percentage of the points (say 90%, 45000 points). If I want an upright ellipse (determined by x^2/a^2 + y^2/b^2 = 1, where a, b are the semi-axes of the ellipse on x, y axes, respectively), and keep the same ratio of the semi-axes (a/b = constant) while changing the area of the ellipse (thus change the percentage of the points it includes). How can Origin give such an ellipse (values of a and b )? Thanks.

easwar

USA
1964 Posts

Posted - 08/18/2005 :  3:01:27 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi injector,

Try the Origin C function pasted below. It does not iteratively change the ellipse area to find the area that covers 90% of the points, but at least gives you a way to try different area values till you get the percentage you want. You could change the code to iterate instead.

Here is what you need to do:
1> Copy-paste the code below to an Origin C file and load and compile the file. Close Code Builder (this will make the computation run faster).
2> Go to your graph that has the scatter data and draw a circle using the Circle Tool button on the Tools toolbar
3> Right-click on the drawn circle, select Label control from context menu, and change Object Name property to: ellipse
4> Go to the script window and type command such as:

compute_ellipse 20.0 0.5;


where 20.0 is area and 0.5 is the a/b ratio.
The program will then position the ellipse and report the percentage of points in the active data plot that fall within the ellipse.

You can then issue more commands changing the area parameter until you get the percentage that you want.

Easwar
OriginLab


void compute_ellipse(double dArea, double dRatio, string strObject = "ellipse")
{
// Point to active graph layer and check if object exists
GraphLayer gly = Project.ActiveLayer();
if( !gly )
{
out_str("Active layer is not a graph layer!");
return;
}
GraphObject gobj;
gobj = gly.GraphObjects(strObject);
if( !gobj )
{
printf("Could not find graph object %s\n", strObject);
return;
}

// Set ellipse fill color to none
gobj.Shape.Fill.Color.nVal = -4;
// Set ellipse border color to red
gobj.Shape.Border.Color.nVal = 1;
// Set ellipse attachment to layer and scale
gobj.Shape.Dimension.Attachment.nVal = 1;

if( dArea < 0 || dRatio < 0 )
{
out_str("Invalid area or ratio value!");
return;
}

// Compute a, b from area and ratio
// area = PI * a * b
// a/b = ratio
// area = PI * a * a/ratio
// a = sqrt( area * ratio / PI )
// b = a / ratio
double a = sqrt( dArea * dRatio / PI );
double b = a / dRatio;

// Set ellipse size properties using a,b
gobj.Shape.Dimension.Top.dVal = b;
gobj.Shape.Dimension.Left.dVal = -a;
gobj.Shape.Dimension.Width.dVal = 2 * a;
gobj.Shape.Dimension.Height.dVal = -2 * b;

// Point to active curve and make copy
using curve = Project.ActiveCurve();
int nMissing;
Curve crv(curve, nMissing, 0, CURVECOPY_SKIP_MISSING_INSIDE);
Dataset dsX;
crv.AttachX(dsX);

// Loop over all x,y values and compute percentage of pts inside ellipse
int nSize = crv.GetSize();
int iInside = 0;
for(int iPt = 0; iPt < crv.GetSize(); iPt++)
{
if( ((dsX[iPt]^2 / a^2) + (crv[iPt]^2 / b^2)) <= 1 ) iInside++;
}
double dPerc = 100.0 * iInside / nSize;

// Report findings
printf("Area of ellipse = \t%f\n", PI * a * b);
printf("Semi-axis a = \t\t%f\n", a);
printf("Semi-axis b = \t\t%f\n", b);
printf("Ratio a/b = \t\t%f\n", a / b);
printf("Perc. of pts. inside = \t%f\n\n", dPerc);
}




Edited by - easwar on 08/18/2005 3:06:33 PM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000