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