Sphere Line Intersect Plugin Challenge
-
There have been a number of posting related to intersect of two lines when the intersect point does not occur at snap point. Given the fact SU professes to be a 3d model tool this seems to be a very basic capability it should have so why not a plugin? The link http://sketchup.google.com/3dwarehouse/details?mid=2ccb7e7f6ae21ba29f30f02514717f00 is a model of the test geo , a spread sheet calculation solution and URL to the math backup. Anyone game ????? BTW the two test lines are form a previous post related to drawing the shortest d between the two
-
I'm sorry, I don't understand the request.
-
Your 5 conditions are more complex than you say:
Let's call the points at the vertices of the line 'L2'p0
andp1
.
Let's call the 'ref point'pt
- it is also the center of the sphere.
Let's call the sphere's radiusrad
puts 'outside' if pt.distance_to_line(p0,p0.vector_to(p1))>rad
No further action needed as no intersections possible
2/3/4.
puts 'inside' if pt.distance_to_line(p0,p0.vector_to(p1))<rad puts 'p0 inside' if pt.distance(p0)<rad puts 'p0 outside' if pt.distance(p0)>rad puts 'p0 on sphere' if pt.distance(p0)==rad puts 'p1 inside' if pt.distance(p1)<rad puts 'p1 outside' if pt.distance(p1)>rad puts 'p1 on sphere' if pt.distance(p1)==rad
If you get p0 AND p1 'outside/on' then there are two intersects.
If you get p0 OR p1 'outside/on' there is one intersect.
If you get p0 AND p1 'inside' there are no intersects.- ` puts 'tangential' if pt.distance_to_line([p0,p0.vector_to(p1)])==rad
pi=pt.project_to_line([p0,p0.vector_to(p1)])
now test if pi is between p0/p1 with code below
puts 'L2 intersects sphere' if pi.between?(p0,p1,false)
or
puts 'L2 touches sphere' if pi.between?(p0,p1,true)`
###RickW's class Geom;;Point3d def between?(pt1,pt2,cond) d1=(self.distance(pt1)+self.distance(pt2)) d2=pt1.distance(pt2)+0 if (d1<=d2) || (d1-d2<1e-10) if cond return true else return true if self!=pt1 && self!=pt2 end end return nil end end #class Geom;;Point3d
However since your aim seems to be to rotate L1 so it 'intersects' with L2 you can simply forget all of this sphere stuff and think laterally...
This is the thought-code...
We have the "rotation point" which we've called 'pt
'.
We have the Line of L2 asline2=[p0,p0.vector_to(p1)]
We can get the nearest point online2
frompt
thuspin=pt.project_to_line(line2)
We can now simply make a transformation for the vertex of L1 [we'll call if by variable 'ed
'] that isn't atpt
and move it to be atpin
.
verts=ed.vertices vert=verts[0] verts.each{|v|vert=v if v.position!=pt} pe=vert.position tr=Geom::Transformation.translation(pe.vector_to(pin)) entities.transform_entities(vert, tr)
NOTE: this moves the end of L1 to intersect with L2 - it will change the length of L1.
IF you want to simply 'swing' L1 round to align with vectorvec=pt.vector_to(pin)
AND leave its end the same distance from 'pt
' then you could contrive a rotation transformation for 'vert
' as if straightforward to find the angle_between the vector of L1 and '[ruby:1uj5gx2c]vec[/ruby:1uj5gx2c]', get a perpendicular by using '[ruby:1uj5gx2c].cross[/ruby:1uj5gx2c]' on them and with that make a rotation transformation to rotate 'vert
' over '[ruby:1uj5gx2c]vec[/ruby:1uj5gx2c]'. Alternatively do like we have above but re-castpin
- first get the intersection pointpin
now offset a clone ofpt
towardspin
the length of L1 this gives a value for an alternative point for 'pin
': thus [ruby:1uj5gx2c]pin=pt.offset(pt.vector_to(pin), ed.length)[/ruby:1uj5gx2c] now use thispin
in the 'translation' ofvert
using [ruby:1uj5gx2c]pe[/ruby:1uj5gx2c] topin
, so that the end of L1 now moves but remains the same distance frompt
as it was before, BUT is now realigned over [ruby:1uj5gx2c]vec[/ruby:1uj5gx2c]...This is untried and might be full of typos BUT you should get the idea...
-
TIG and Chris
Thanks for the replys!
I did not make myself very clear sorry.
I have created a spread sheet that solves the problem for my use but did not put the logic for the five cases in it. I am not a ruby programmer and thought a plugin would be more useful for the number of folks who have posted this question in the past plus thinking this is a capability any 3d model program should have. Given the fact the ref URL has c, lisp, etc code examples I thought it may be easy to create a plugin. I'll leave it up to your expertise if that is a reasonable thing to do. If have found doing this manually and using the interpolation scheme Jeane Lemire ( I think ) gets problematic for this case because one winds up trying to interpolate in two dimensions.TIG:
The five cases are from the ref and the only ones I can ID also. The range of solutions for solving the quadratic equation in the ref give you the info( sign and magnitude of u) to make a decision on where the line segment lies and if there are intersections and how many.
One wants to keep the line segment for L1 the same and you can either rotate or do an x,y,z move of L1's vertex as I did in the skip. I tried solving the problem for rotation( theta and phi) using the standard form of the line in space( intersection of two planes ) I get a trig equation in two variables I cannot reduce by the standard approaches.
Thanks again !!
Advertisement