discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: Determining X and Y for the intersection of a conic section and rotated plane given Y

A
adrianv
Fri, Jun 18, 2021 10:49 PM

I still don't really understand what you need.  The code I wrote does provide
separate access to the x, y and z coordinates.  That is, the final loop that
draws the lines is producing the line endpoints (in the "int") variable, so
int.x, int.y and int.z are the separate coordinates of the end of the line
that traces the ellipse.

If you want to be able to specify a y and get the corresponding x and z then
the same approach works.  You just have to sample the cone at the specified
y instead of by angle.

I suggested this approach because it appears to be the simplest way to get
(what I thought) you wanted.  It requires the smallest amount of
mathematical knowledge.  You can of course just write down the equation of
your cone and the equation of your plane and substitute the plane equation
into the cone equation to get an equation for the ellipse, and then you can
plug in y and get x and z out.  I was less enthusiastic about that approach
because it means more work for the human instead of leaning on the computer
to do the work for you.  It's a math solution instead of an OpenSCAD
solution.

Your cone has an equation like y^2+z^2=(tan(15)x)^2 and the plane is
something like -x+z=0.  So subsitute x=z into the first, and solve,  You
get x=real_roots([  1-sqr(tan(15)), -2
apex.z, sqr(apex.z)+sqr(y-apex.y)],
using BOSL2, but it's just a quadratic so you can use the quadratic formula.

OpenSCAD mailing list-2 wrote

Thank you.
What I'm trying to do is to feed X and Z into a module along w/ Y so that
I can write out the coordinates.
Unfortunately, I can't figure out how to unwrap your code to fit the
requirements of the module I worked up:
include<BOSL2/std.scad>$fn=80;
difference(){
  translate([0, 0.125, 0.25])
    rotate([0, 90, 0])
    cylinder(r1=0, r2=0.125, h=(0.125 / tan(15)), center=false);
  cube([1, 1, 0.25], center=false);
  rotate([0, 45, 0])
     cube([1, 1, 1], center=false);
} plane = plane_from_normal([-1,0,1]);
apex = [0, 1/8, 1/4];
rbase = 0.125;
h = 0.125/tan(15);
N = 16;
//base = [for(i=[0:1:N/2]) let(theta=360i/N) apex+[h,rbasecos(theta),
rbase*sin(theta)]]; color("red")
//  for(pt=base)
    for(i=[0:1:N/2])
{
//     int = plane_line_intersection(plane, [apex, pt]);
     stroke([apex,plane_line_intersection(plane, [apex, pt])],
width=0.005);
  }

I want to have separate access to the X, Y, and, Z coordinates:
module cutv(bx, by, bz, ex, ey, ez, r, a) {
  hull(){
    translate([bx, by, bz]){
      vendmill(r, a);
    }
    translate([ex, ey, ez]){
      vendmill(r, a);
    }
  }
}
(see below for the dependencies)

Eventually the module will be extended to write out the coordinates as
G-Code using echo.
Another limitation is I do most of my development in BlockSCAD, which I
guess makes my code overly simplistic/procedural/stilted.
William

module vendmill(vr, va) {
  union(){
    removevshape(vr, va);
    translate([0, 0, (calcVdepth(vr, va))]){
      cylinder(r1=vr, r2=vr, h=st, center=false);
    }
  }
}

module removevshape(vr, va) {
  cylinder(r1=0, r2=vr, h=(calcVdepth(vr, va)), center=false);
}
function calcVdepth(rad, an) = rad / tan(an);


OpenSCAD mailing list
To unsubscribe send an email to

discuss-leave@.openscad

I still don't really understand what you need. The code I wrote does provide separate access to the x, y and z coordinates. That is, the final loop that draws the lines is producing the line endpoints (in the "int") variable, so int.x, int.y and int.z are the separate coordinates of the end of the line that traces the ellipse. If you want to be able to specify a y and get the corresponding x and z then the same approach works. You just have to sample the cone at the specified y instead of by angle. I suggested this approach because it appears to be the simplest way to get (what I thought) you wanted. It requires the smallest amount of mathematical knowledge. You can of course just write down the equation of your cone and the equation of your plane and substitute the plane equation into the cone equation to get an equation for the ellipse, and then you can plug in y and get x and z out. I was less enthusiastic about that approach because it means more work for the human instead of leaning on the computer to do the work for you. It's a math solution instead of an OpenSCAD solution. Your cone has an equation like y^2+z^2=(tan(15)*x)^2 and the plane is something like -x+z=0. So subsitute x=z into the first, and solve, You get x=real_roots([ 1-sqr(tan(15)), -2*apex.z, sqr(apex.z)+sqr(y-apex.y)], using BOSL2, but it's just a quadratic so you can use the quadratic formula. OpenSCAD mailing list-2 wrote > Thank you. > What I'm trying to do is to feed X and Z into a module along w/ Y so that > I can write out the coordinates. > Unfortunately, I can't figure out how to unwrap your code to fit the > requirements of the module I worked up: > include&lt;BOSL2/std.scad&gt;$fn=80; > difference(){ >   translate([0, 0.125, 0.25]) >     rotate([0, 90, 0]) >     cylinder(r1=0, r2=0.125, h=(0.125 / tan(15)), center=false); >   cube([1, 1, 0.25], center=false); >   rotate([0, 45, 0]) >      cube([1, 1, 1], center=false); > } plane = plane_from_normal([-1,0,1]); > apex = [0, 1/8, 1/4]; > rbase = 0.125; > h = 0.125/tan(15); > N = 16; > //base = [for(i=[0:1:N/2]) let(theta=360*i/N) apex+[h,rbase*cos(theta), > rbase*sin(theta)]]; color("red") > //  for(pt=base) >     for(i=[0:1:N/2]) > { > //     int = plane_line_intersection(plane, [apex, pt]); >      stroke([apex,plane_line_intersection(plane, [apex, pt])], > width=0.005); >   } > > > I want to have separate access to the X, Y, and, Z coordinates: > module cutv(bx, by, bz, ex, ey, ez, r, a) { >   hull(){ >     translate([bx, by, bz]){ >       vendmill(r, a); >     } >     translate([ex, ey, ez]){ >       vendmill(r, a); >     } >   } > } > (see below for the dependencies) > > Eventually the module will be extended to write out the coordinates as > G-Code using echo. > Another limitation is I do most of my development in BlockSCAD, which I > guess makes my code overly simplistic/procedural/stilted. > William > > module vendmill(vr, va) { >   union(){ >     removevshape(vr, va); >     translate([0, 0, (calcVdepth(vr, va))]){ >       cylinder(r1=vr, r2=vr, h=st, center=false); >     } >   } > } > > module removevshape(vr, va) { >   cylinder(r1=0, r2=vr, h=(calcVdepth(vr, va)), center=false); > } > function calcVdepth(rad, an) = rad / tan(an); > > > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to > discuss-leave@.openscad -- Sent from: http://forum.openscad.org/
WF
William F. Adams
Sat, Jun 19, 2021 3:41 AM

Thanks!
As I noted, I wasn't able to get the numbers out of your code, but with the explanation you've provided I think I'll be able to puzzle things out.
William

Thanks! As I noted, I wasn't able to get the numbers out of your code, but with the explanation you've provided I think I'll be able to puzzle things out. William