{ "cells": [ { "cell_type": "code", "execution_count": 414, "metadata": {}, "outputs": [], "source": [ "from IPython.core.display import HTML\n", "import numpy as np\n", "import math" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[x3d](https://pypi.org/project/x3d) is a [PyPI](https://pypi.org) distributed Python package maintained by the \n", "[Web3D Consortium](https://web3d.org). See also a local help file [x3d.x3d](x3d.x3d.html) explaining the import statement \n", "\n", "`from x3d import x3d` ." ] }, { "cell_type": "code", "execution_count": 415, "metadata": {}, "outputs": [], "source": [ "from x3d import x3d" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[common_geometry](common_geometry.html) is a Python package, local to this Jupyter notebook folder, which defines convenience classes for generating X3D elements with the geometric definitition pertinent to this notebook. See [common_geometry.py](common_geometry.py) for Python source code; [common_geometry](common_geometry.html) for documentation autogenerated by the [pydoc](https://docs.python.org/3/library/pydoc.html) documentation system.\n" ] }, { "cell_type": "code", "execution_count": 416, "metadata": {}, "outputs": [], "source": [ "import common_geometry" ] }, { "cell_type": "code", "execution_count": 417, "metadata": {}, "outputs": [], "source": [ "alpha_degrees = 30.0 # the half angle of the cone\n", "beta_degrees = 30.0 # the angle the intersecting plane makes with horizontal\n", "a = 1.0 # distance of intersecting plane to cone vertex\n", "f = 2.5 # total height of cone\n", "\n", "if (alpha_degrees + beta_degrees >= 90.0):\n", " raise AssertionError(\"choice of alpha , beta angles geometrically invalid\")\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 418, "metadata": {}, "outputs": [], "source": [ "class InscribedSphere:\n", " \"\"\"\n", " data structure with named fields describing sphere inscribed (internally tangent)\n", " to a cone with intersection with plane\n", " \"\"\"\n", " def __init__(self):\n", " self.center = np.array((0.,0.,0.))\n", " self.radius = 0.0\n", " # focus is the point of tangency with the plane\n", " self.focus = np.array((0.,0.,0.))\n", " # contact_circle is the circular section where the sphere is in tangent contact with the cone\n", " self.contact_circle_center = ((0.,0.,0.))\n", " self.contact_circle_radius = 0.\n", " \n", " def contact_circle_point(self, theta):\n", " \"\"\"\n", " returns a (3,) array of a point\n", " on the circle, theta a cclockwise rotation (relative to y axis) from the x axis\n", " \"\"\"\n", " return self.contact_circle_center + self.contact_circle_radius * np.array((math.cos(theta),0.0, math.sin(theta)))" ] }, { "cell_type": "code", "execution_count": 419, "metadata": {}, "outputs": [], "source": [ "# convert angles to radians\n", "alpha = math.radians(alpha_degrees)\n", "beta = math.radians(beta_degrees)\n" ] }, { "cell_type": "code", "execution_count": 420, "metadata": {}, "outputs": [], "source": [ "# coordinates of points and direction vectors\n", "pointC = np.array((0.,0.,0.))\n", "axis = np.array((0.,-1.,0.)) # axis of cone, pointing to open end\n", "pointB = pointC - a * axis\n", "\n", "z = np.array((0.,0.,1.0)) # global z axis\n", "normal = np.array((math.sin(beta), math.cos(beta),0.0))\n", "\n", "ua = np.cross(z, normal) # a unit vector in inclined plane, largely in -x direction for beta > 0\n", " # will be along semimajor axis of ellipse\n", "ub = np.cross(normal, ua) # will be along semiminor axis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Evaluation of geometry of the upper inscribed sphere\n", " \n", "∡CBA = alpha\n", "\n", "∡ACB = pi/2 - beta\n", "\n", "∣AD is bisector of ∡BAC\n", "\n", "DE ⊥ AC\n", "\n", "\n", "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![Drawing of upper sphere](top_drawing.png)" ] }, { "cell_type": "code", "execution_count": 421, "metadata": {}, "outputs": [], "source": [ "angCBA=alpha # alpha is half angle of cone\n", "\n", "angBAC= math.pi/2 + beta - alpha # angles in triangle sum to pi\n", "angDAC= angBAC/2 # AD segment is angle bisector of angle BAC\n", "angACD= math.pi/2 - beta # beta is angle that segment AC makes with horizontal\n", "angCDA= math.pi - angDAC - angACD # angles in triangle sum to pi\n", "\n", "# now apply law of sines\n", "disBC = a # definition of cone dimension a\n", "disAC = math.sin(angCBA) * disBC / math.sin(angBAC) # law of sines\n", "disCD = math.sin(angDAC) * disAC / math.sin(angCDA) # law of sines\n", "disBD = disBC - disCD\n", "disDH = disBD * math.sin(angCBA)\n", "disDF = disDH * math.sin(angCBA)\n", "disFH = disDH * math.cos(angCBA)\n", "\n", "disDE = disCD * math.sin(angACD)\n", "disCE = disCD * math.cos(angACD)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 422, "metadata": {}, "outputs": [], "source": [ "upperSphere = InscribedSphere()\n", "upperSphere.radius = disDE\n", "upperSphere.center = pointC - disCD * axis\n", "upperSphere.focus = pointC + disCE * ua\n", "upperSphere.contact_circle_center = upperSphere.center - disDF * axis\n", "upperSphere.contact_circle_radius = disFH" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Evaluation of geometry of the lower inscribed sphere\n", "\n", "∡CBA = alpha\n", "\n", "∡ACB = pi/2 - beta\n", "\n", "∣AD is bisector of ∡BAC\n", "\n", "DE ⊥ AC\n" ] }, { "cell_type": "code", "execution_count": 423, "metadata": {}, "outputs": [], "source": [ "disBC = a\n", "angCBA=alpha\n", "angACB= math.pi/2 + beta\n", "angBAC= math.pi - angCBA - angACB\n", "\n", "angCAD = (math.pi-angBAC)/2\n", "angDCA = math.pi/2 - beta\n", "angADC = math.pi - angCAD - angDCA\n", "\n", "disAC = math.sin(angCBA) * disBC/math.sin(angBAC)\n", "disCD = math.sin(angCAD) * disAC/math.sin(angADC)\n", "disAD = math.sin(angDCA) * disAC/math.sin(angADC)\n", "disDE = disAD * math.sin(angCAD)\n", "disCE = disCD * math.cos(angDCA)\n", "\n", "disBD = disBC + disCD\n", "disDH = disBD * math.sin(angCBA)\n", "disDF = disDH * math.sin(angCBA)\n", "disFH = disDH * math.cos(angCBA)\n", "\n" ] }, { "cell_type": "code", "execution_count": 424, "metadata": {}, "outputs": [], "source": [ "lowerSphere = InscribedSphere()\n", "lowerSphere.radius = disDE\n", "lowerSphere.center = pointC + disCD * axis\n", "lowerSphere.focus = pointC - disCE * ua\n", "lowerSphere.contact_circle_center = lowerSphere.center - disDF * axis\n", "lowerSphere.contact_circle_radius = disFH\n" ] }, { "cell_type": "code", "execution_count": 425, "metadata": {}, "outputs": [], "source": [ "\n", "sc = x3d.Scene()\n", "sc.children.append( x3d.Background(skyColor = [(1,1,1)]) )\n", "\n", "cone_shape = common_geometry.Cone(\n", " vertex_height = a,\n", " total_height = f,\n", " half_angle = alpha,\n", " appearance = x3d.Appearance(\n", " material = x3d.Material( diffuseColor=(0.0,0.5,0.5),transparency=0.75)\n", " )\n", ")\n", "\n", "\n", "plane_shape = common_geometry.TiltedPlane(\n", " length = 2.5,\n", " width = 2.5, \n", " beta = beta, \n", " appearance= x3d.Appearance( material = x3d.Material( emissiveColor=(0.8,0.6,0.6), \n", " diffuseColor=(0.8,0.6,0.6),transparency=0.2)) )\n", "\n", "upper_sphere = common_geometry.Sphere( \n", " center = upperSphere.center,\n", " radius = upperSphere.radius * 0.995 ,\n", " appearance = x3d.Appearance( material = x3d.Material( diffuseColor=(1,1,0), transparency=0.0) )\n", ")\n", "\n", "\n", "upper_focus = common_geometry.Sphere( \n", " center = upperSphere.focus,\n", " radius = 0.02 ,\n", " appearance = x3d.Appearance( material = x3d.Material( diffuseColor=(0,0,0), transparency=0.0) )\n", ")\n", "contact_circle_appearance = x3d.Appearance( \n", " lineProperties = x3d.LineProperties( linewidthScaleFactor=1 ),\n", " material= x3d.Material( emissiveColor = (0,0,1)) )\n", "\n", "upper_contact_circle = common_geometry.Circle(\n", " center = upperSphere.contact_circle_center,\n", " radius = upperSphere.contact_circle_radius,\n", " appearance = contact_circle_appearance\n", ")\n", "\n", "lower_sphere = common_geometry.Sphere( \n", " center = lowerSphere.center,\n", " radius = lowerSphere.radius * 0.995,\n", " appearance = x3d.Appearance( material = x3d.Material( diffuseColor=(1,1,0.0)) )\n", ")\n", "\n", "lower_focus = common_geometry.Sphere( \n", " center = lowerSphere.focus,\n", " radius = 0.02 ,\n", " appearance = x3d.Appearance( material = x3d.Material( diffuseColor=(0,0,0), transparency=0.0) )\n", ")\n", "\n", "lower_contact_circle = common_geometry.Circle(\n", " center = lowerSphere.contact_circle_center,\n", " radius = lowerSphere.contact_circle_radius,\n", " appearance = contact_circle_appearance\n", ")\n", "\n", "\n", "figure = x3d.Transform(\n", " rotation=(0, -1, 0 ,math.radians(20.0)),\n", " children = [\n", " cone_shape,\n", " plane_shape,\n", " upper_sphere,\n", " upper_contact_circle,\n", " upper_focus,\n", " lower_sphere,\n", " lower_contact_circle,\n", " lower_focus\n", " ]\n", ")\n", "sc.children.append(figure)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Explicitly construct the ellipse which is the intersection between the plane and the cone.\n", "\n", "Will start with a circle, then stretch it by different scales in x and z axis to be the appropriate\n", "ellipse, then rotate it around the z axis" ] }, { "cell_type": "code", "execution_count": 426, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "semiminor axis: 0.61237\n", "semimajor axis: 0.75000\n" ] } ], "source": [ "ellipse_center = 0.5 * (lowerSphere.focus + upperSphere.focus)\n", "# c is 1/2 distance between foci\n", "c = 0.5 * np.sqrt( np.square( lowerSphere.focus - upperSphere.focus).sum())\n", "\n", "semimajor = 0.5 * np.sqrt( np.square( lowerSphere.contact_circle_center - upperSphere.contact_circle_center).sum())/ math.cos(alpha)\n", "semiminor = np.sqrt( np.square(semimajor) - np.square(c))\n", "\n", "print(\"semiminor axis: %.5f\" % semiminor)\n", "print(\"semimajor axis: %.5f\" % semimajor)\n", "\n", "def ellipse_point(theta):\n", " \"\"\"\n", " for theta an angle in radians, returns point on ellipse that makes angle theta measured from center\n", " relative to major axis\n", " \"\"\"\n", " return ellipse_center + \\\n", " math.cos(theta) * semimajor * ua + \\\n", " math.sin(theta) * semiminor * ub" ] }, { "cell_type": "code", "execution_count": 427, "metadata": {}, "outputs": [], "source": [ "ellipse_line_properties = x3d.LineProperties( applied=True, linewidthScaleFactor=3)\n", "ellipse_material = x3d.Material(emissiveColor=(0,0,0))\n", "\n", "appearance = x3d.Appearance( lineProperties = ellipse_line_properties, material=ellipse_material )\n", "\n", "circular_shape = x3d.Transform(\n", " rotation = (1.0, 0.0, 0.0, math.pi/2),\n", " children=[\n", " x3d.Shape(\n", " geometry = x3d.Circle2D(radius=1.0),\n", " appearance = appearance\n", " )\n", " ]\n", ")\n", "\n", "ellipse_shape = x3d.Transform(\n", " translation = tuple(ellipse_center),\n", " children=[x3d.Transform(\n", " rotation=(0 , 0, -1, beta),\n", " children=[\n", " x3d.Transform(\n", " scale = (semimajor,1,semiminor),\n", " children = [circular_shape]\n", " )\n", " ]\n", " ) ]\n", ")\n", "figure.children.append(ellipse_shape)" ] }, { "cell_type": "code", "execution_count": 428, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "phi 0.570\n" ] } ], "source": [ "# create polyline: upper focus to ellipse to upper contact circle\n", "theta = math.pi * 0.75\n", "ep = ellipse_point(theta)\n", "phi = math.atan2(ep[2], ep[0])\n", "print(\"phi %.3f\" % phi)\n", "polyline_vertices = x3d.Coordinate(\n", "[tuple(p) for p in \\\n", "[\n", " upperSphere.focus,\n", " ellipse_point(theta),\n", " upperSphere.contact_circle_point(phi),\n", " lowerSphere.focus,\n", " ellipse_point(theta),\n", " lowerSphere.contact_circle_point(phi), \n", "]\n", "]\n", ")\n", "polyline_vertices.DEF='foci_segments'\n", "\n", "polyline_indices = [0,1,2,-1,3,4,5,-1]\n", "polyline_colors = x3d.Color(color=[(0,0,1),(1,0,0)])\n", "\n", "polyline = x3d.Shape(\n", " geometry = x3d.IndexedLineSet(\n", " colorPerVertex=False,\n", " coord = polyline_vertices,\n", " color = polyline_colors,\n", " coordIndex = polyline_indices,\n", " colorIndex = [0,1],\n", " ),\n", " appearance = x3d.Appearance( lineProperties = ellipse_line_properties, material=ellipse_material )\n", ")\n", "\n", "figure.children.append(polyline)" ] }, { "cell_type": "code", "execution_count": 429, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[(-0.1584936490538903, 0.09150635094610962, 0.0), (-0.4330127018922193, 0.2499999999999999, 0.0), (-0.274519052838329, 0.5245190528383289, 3.3618887936342276e-17), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.4330127018922193, 0.2499999999999999, 0.0), (-1.0245190528383286, -0.7745190528383287, 1.2546739787239372e-16), (-0.1584936490538903, 0.09150635094610962, 0.0), (-0.42053237541917143, 0.2427944801512113, 0.1194679356736933), (-0.26406982904243154, 0.5245190528383289, 0.07501890268961717), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.42053237541917143, 0.2427944801512113, 0.1194679356736933), (-0.9855220187323815, -0.7745190528383287, 0.27997435636571666), (-0.1584936490538903, 0.09150635094610962, 0.0), (-0.38357100794733945, 0.22145482469173244, 0.2343447855778368), (-0.23425834742389046, 0.5245190528383289, 0.14312140662207418), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.38357100794733945, 0.22145482469173244, 0.2343447855778368), (-0.8742640546830807, -0.7745190528383287, 0.5341363611643053), (-0.1584936490538903, 0.09150635094610962, 0.0), (-0.32354900410049214, 0.1868011046134544, 0.3402158967942938), (-0.18918051634808303, 0.5245190528383289, 0.19892572132714756), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.32354900410049214, 0.1868011046134544, 0.3402158967942938), (-0.7060312988131602, -0.7745190528383287, 0.7424008989252021), (-0.1584936490538903, 0.09150635094610962, 0.0), (-0.24277297582573631, 0.1401650429449553, 0.4330127018922192), (-0.13425125780678018, 0.5245190528383289, 0.23945210408044176), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.24277297582573631, 0.1401650429449553, 0.4330127018922192), (-0.5010325151149313, -0.7745190528383287, 0.8936474184074792), (-0.1584936490538903, 0.09150635094610962, 0.0), (-0.1443471005899522, 0.08333883738235086, 0.5091690716927474), (-0.07487422714905587, 0.5245190528383289, 0.26411088671254135), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.1443471005899522, 0.08333883738235086, 0.5091690716927474), (-0.2794344198977294, -0.7745190528383287, 0.9856752480432718), (-0.1584936490538903, 0.09150635094610962, 0.0), (-0.03205382958058431, 0.01850628713690873, 0.5657583596134285), (-0.015528357491639888, 0.5245190528383289, 0.27407951489461063), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.03205382958058431, 0.01850628713690873, 0.5657583596134285), (-0.05795261911689284, -0.7745190528383287, 1.0228786749005172), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.08979146977226926, -0.0518411292439518, 0.6006058710551089), (0.04058990650522012, 0.5245190528383289, 0.2715016940299835), (0.5915063509461093, -0.34150635094610937, 0.0), (0.08979146977226926, -0.0518411292439518, 0.6006058710551089), (0.1514835933519519, -0.7745190528383287, 1.0132581164609176), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.21650635094610945, -0.12499999999999985, 0.6123724356957944), (0.09150635094610958, 0.5245190528383289, 0.2588190451025208), (0.5915063509461093, -0.34150635094610937, 0.0), (0.21650635094610945, -0.12499999999999985, 0.6123724356957944), (0.3415063509461092, -0.7745190528383287, 0.965925826289068), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.3432212321199496, -0.1981588707560479, 0.6006058710551089), (0.13620493952643523, 0.5245190528383289, 0.23834622887692894), (0.5915063509461093, -0.34150635094610937, 0.0), (0.3432212321199496, -0.1981588707560479, 0.6006058710551089), (0.5083237545545024, -0.7745190528383287, 0.8895202359611387), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.4650665314728032, -0.26850628713690844, 0.5657583596134285), (0.1743233574166868, 0.5245190528383289, 0.21206621001523873), (0.5915063509461093, -0.34150635094610937, 0.0), (0.4650665314728032, -0.26850628713690844, 0.5657583596134285), (0.6505836268250637, -0.7745190528383287, 0.7914418703454424), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.5773598024821709, -0.3333388373823505, 0.5091690716927476), (0.2058918393738914, 0.5245190528383289, 0.18157439480964538), (0.5915063509461093, -0.34150635094610937, 0.0), (0.5773598024821709, -0.3333388373823505, 0.5091690716927476), (0.7683988054071726, -0.7745190528383287, 0.6776448667831669), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.6757856777179552, -0.390165042944955, 0.43301270189221924), (0.23114033527913153, 0.5245190528383289, 0.1481042058089639), (0.5915063509461093, -0.34150635094610937, 0.0), (0.6757856777179552, -0.390165042944955, 0.43301270189221924), (0.8626274749402234, -0.7745190528383287, 0.5527324208936907), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.7565617059927112, -0.4368011046134542, 0.3402158967942938), (0.2503691536682408, 0.5245190528383289, 0.11258773140401258), (0.5915063509461093, -0.34150635094610937, 0.0), (0.7565617059927112, -0.4368011046134542, 0.3402158967942938), (0.934390402137894, -0.7745190528383287, 0.4201831339086928), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.8165837098395584, -0.4714548246917322, 0.23434478557783683), (0.2638681047327746, 0.5245190528383289, 0.07572538330036213), (0.5915063509461093, -0.34150635094610937, 0.0), (0.8165837098395584, -0.4714548246917322, 0.23434478557783683), (0.9847691733596201, -0.7745190528383287, 0.2826109778995791), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.8535450773113904, -0.4927944801512111, 0.11946793567369351), (0.27186891913218497, 0.5245190528383289, 0.03805261070085376), (0.5915063509461093, -0.34150635094610937, 0.0), (0.8535450773113904, -0.4927944801512111, 0.11946793567369351), (1.0146286192001484, -0.7745190528383287, 0.1420142764962253), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.8660254037844383, -0.49999999999999967, 7.49939943260923e-17), (0.274519052838329, 0.5245190528383289, 2.3772143635738242e-17), (0.5915063509461093, -0.34150635094610937, 0.0), (0.8660254037844383, -0.49999999999999967, 7.49939943260923e-17), (1.0245190528383286, -0.7745190528383287, 8.871884785340021e-17), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.8535450773113904, -0.4927944801512111, -0.11946793567369338), (0.27186891913218497, 0.5245190528383289, -0.03805261070085371), (0.5915063509461093, -0.34150635094610937, 0.0), (0.8535450773113904, -0.4927944801512111, -0.11946793567369338), (1.0146286192001484, -0.7745190528383287, -0.14201427649622514), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.8165837098395584, -0.4714548246917322, -0.23434478557783675), (0.2638681047327746, 0.5245190528383289, -0.0757253833003621), (0.5915063509461093, -0.34150635094610937, 0.0), (0.8165837098395584, -0.4714548246917322, -0.23434478557783675), (0.9847691733596201, -0.7745190528383287, -0.282610977899579), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.7565617059927112, -0.4368011046134542, -0.3402158967942937), (0.2503691536682408, 0.5245190528383289, -0.11258773140401257), (0.5915063509461093, -0.34150635094610937, 0.0), (0.7565617059927112, -0.4368011046134542, -0.3402158967942937), (0.934390402137894, -0.7745190528383287, -0.4201831339086927), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.6757856777179553, -0.3901650429449551, -0.4330127018922192), (0.23114033527913155, 0.5245190528383289, -0.14810420580896388), (0.5915063509461093, -0.34150635094610937, 0.0), (0.6757856777179553, -0.3901650429449551, -0.4330127018922192), (0.8626274749402235, -0.7745190528383287, -0.5527324208936906), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.5773598024821711, -0.3333388373823506, -0.5091690716927475), (0.20589183937389144, 0.5245190528383289, -0.18157439480964532), (0.5915063509461093, -0.34150635094610937, 0.0), (0.5773598024821711, -0.3333388373823506, -0.5091690716927475), (0.7683988054071728, -0.7745190528383287, -0.6776448667831667), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.4650665314728036, -0.26850628713690866, -0.5657583596134284), (0.17432335741668692, 0.5245190528383289, -0.21206621001523865), (0.5915063509461093, -0.34150635094610937, 0.0), (0.4650665314728036, -0.26850628713690866, -0.5657583596134284), (0.6505836268250641, -0.7745190528383287, -0.7914418703454421), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.3432212321199499, -0.19815887075604807, -0.6006058710551088), (0.1362049395264354, 0.5245190528383289, -0.23834622887692886), (0.5915063509461093, -0.34150635094610937, 0.0), (0.3432212321199499, -0.19815887075604807, -0.6006058710551088), (0.5083237545545031, -0.7745190528383287, -0.8895202359611384), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.2165063509461096, -0.12499999999999994, -0.6123724356957944), (0.09150635094610965, 0.5245190528383289, -0.2588190451025208), (0.5915063509461093, -0.34150635094610937, 0.0), (0.2165063509461096, -0.12499999999999994, -0.6123724356957944), (0.3415063509461094, -0.7745190528383287, -0.9659258262890679), (-0.1584936490538903, 0.09150635094610962, 0.0), (0.08979146977226929, -0.05184112924395182, -0.6006058710551089), (0.04058990650522012, 0.5245190528383289, -0.2715016940299835), (0.5915063509461093, -0.34150635094610937, 0.0), (0.08979146977226929, -0.05184112924395182, -0.6006058710551089), (0.1514835933519519, -0.7745190528383287, -1.0132581164609176), (-0.1584936490538903, 0.09150635094610962, 0.0), (-0.03205382958058442, 0.018506287136908786, -0.5657583596134285), (-0.015528357491639949, 0.5245190528383289, -0.27407951489461063), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.03205382958058442, 0.018506287136908786, -0.5657583596134285), (-0.05795261911689307, -0.7745190528383287, -1.0228786749005172), (-0.1584936490538903, 0.09150635094610962, 0.0), (-0.14434710058995187, 0.08333883738235069, -0.5091690716927476), (-0.07487422714905569, 0.5245190528383289, -0.2641108867125414), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.14434710058995187, 0.08333883738235069, -0.5091690716927476), (-0.2794344198977287, -0.7745190528383287, -0.985675248043272), (-0.1584936490538903, 0.09150635094610962, 0.0), (-0.2427729758257362, 0.14016504294495524, -0.4330127018922193), (-0.13425125780678007, 0.5245190528383289, -0.23945210408044185), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.2427729758257362, 0.14016504294495524, -0.4330127018922193), (-0.5010325151149309, -0.7745190528383287, -0.8936474184074794), (-0.1584936490538903, 0.09150635094610962, 0.0), (-0.32354900410049214, 0.1868011046134544, -0.3402158967942938), (-0.18918051634808303, 0.5245190528383289, -0.19892572132714756), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.32354900410049214, 0.1868011046134544, -0.3402158967942938), (-0.7060312988131602, -0.7745190528383287, -0.7424008989252021), (-0.1584936490538903, 0.09150635094610962, 0.0), (-0.3835710079473392, 0.22145482469173233, -0.2343447855778372), (-0.23425834742389035, 0.5245190528383289, -0.14312140662207434), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.3835710079473392, 0.22145482469173233, -0.2343447855778372), (-0.8742640546830802, -0.7745190528383287, -0.534136361164306), (-0.1584936490538903, 0.09150635094610962, 0.0), (-0.4205323754191713, 0.24279448015121124, -0.1194679356736936), (-0.2640698290424315, 0.5245190528383289, -0.07501890268961739), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.4205323754191713, 0.24279448015121124, -0.1194679356736936), (-0.9855220187323813, -0.7745190528383287, -0.2799743563657175), (-0.1584936490538903, 0.09150635094610962, 0.0), (-0.4330127018922193, 0.2499999999999999, -1.499879886521846e-16), (-0.274519052838329, 0.5245190528383289, -1.555298372001034e-16), (0.5915063509461093, -0.34150635094610937, 0.0), (-0.4330127018922193, 0.2499999999999999, -1.499879886521846e-16), (-1.0245190528383286, -0.7745190528383287, -5.804452545237016e-16)]\n" ] } ], "source": [ "NumKeyFrame = 32\n", "\n", "keys = np.linspace(0.0, 1.0, NumKeyFrame+1, endpoint=True)\n", "key_values = list()\n", "for frac in keys:\n", " theta = 2. * math.pi * frac\n", " ep = ellipse_point(theta)\n", " phi = math.atan2(ep[2], ep[0])\n", " value = [tuple(p) for p in \\\n", " [\n", " upperSphere.focus,\n", " ep,\n", " upperSphere.contact_circle_point(phi),\n", " lowerSphere.focus,\n", " ep,\n", " lowerSphere.contact_circle_point(phi), \n", " ]\n", " ]\n", " \n", "\n", " key_values.extend( value )\n", "\n", "print(key_values)\n", "\n", "interpolator = x3d.CoordinateInterpolator(\n", " key = list(keys),\n", " keyValue = key_values,\n", " DEF = 'foci_segments_interpolator'\n", ")\n", "\n", "sc.children.append(interpolator)\n", "\n", "route1 = x3d.ROUTE(\n", " fromNode = 'foci_segments_interpolator',\n", " fromField = 'value_changed',\n", " toNode = 'foci_segments',\n", " toField = 'point'\n", ")\n", "\n", "sc.children.append(route1)\n", "\n", "time_sensor=x3d.TimeSensor(\n", " DEF = 'timer1',\n", " cycleInterval = 5.0,\n", " enabled=True,\n", " loop = True,\n", ")\n", "sc.children.append(time_sensor)\n", "sc.children.append(\n", " x3d.ROUTE(\n", " fromNode=\"timer1\",\n", " fromField='fraction_changed',\n", " toNode = 'foci_segments_interpolator',\n", " toField = 'set_fraction'\n", " )\n", ")" ] }, { "cell_type": "code", "execution_count": 430, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ " \n", " \n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", " \n", " \n", "" ] }, { "cell_type": "code", "execution_count": 431, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 431, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x3dnode = \"\"\"\\\n", "\n", "%s\n", "\n", "\n", "\"\"\" % sc.HTML5()\n", "\n", "#print(x3dnode)\n", "HTML(x3dnode)" ] }, { "cell_type": "code", "execution_count": 432, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n" ] } ], "source": [ "if (True):\n", " print(sc.XML())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }